Tuesday, December 21, 2010

How to decide where to fit in a particular method inside a class

Hi All,

I think the title is quite interesting/confusing. Yes indeed!. Often from my experience i had seen people are getting confused while deciding about a particular methods place inside a particular class..

let me be little deep in what i am syaing. for instance you have 3 classes i.e. customer, order and Product.. and now you want to get all the orders placed by a customer. The question comes where i need to write the method..do i need to write inside customer or order....

Thumb rule - It purley goes based on the return type... in this case since i want to return all the orders placed by customer, so GetOrdersByCustomer() sits inside the Orders class...since i am returning Orders.

In the similar line, if i have to place an order(where in i am not returning anything), then it purly goes by the input .. ie. since i am placing an order..PlaceOrder() should be there inside Order class.

I hope this helps!.


No comments: