Definition of Object-Oriented programming

Object-Oriented programming. The C# book I’m reading has an excellent definition; it says “… object-oriented programming encapsulates the characteristics and capabilities of an entity in a single, self-contained and self-sustaining unit of code.” Pretty obvious stuff. So my purely theoretical question for the late night: given an object oriented system with classes that describe entities … where in the system do you put the retrieval of objects? For instance, let’s say I have an ecommerce system that has classes ‘Order’, ‘Product’, and ‘Consumer’. Order will have methods like return(), commit(), cancel(), Product will have methods like getPrice(), updateStock() and so on… The bottom line is that methods are the way we access (getting) an objects properties and also the way that we manipulate an objects properties (setting). So lets say that somewhere in this system, I want to be able to query all the orders in system, returning open orders, closed orders, orders over $500.. It doesn’t feel right to write a method like this:

[java]
public static Resultset getOpenOrders()

[c#]
public static DataTable getOpenOrders()

for the Order object. Where does a method like this fit in the system?

3 thoughts on “Definition of Object-Oriented programming”

  1. Have a look at the ‘Factory’ pattern. You would create OrderFactory, ProductFactory and ConsumerFactory classes that would, for example, query a database and return an array of Order, Product and Consumer objects respectively.

  2. AJ – this is a very good post. I’m afraid I can’t help much in this regards except to say I’ve had the same wonderings as you. It’s almost like OO is strong on the “abstract” but not on the implementation. In ColdFusion, it’s pretty obvious. I ‘get’ stuff from index.cfm. There is no reason for index.cfm to be an object – it’s just a resource.

Leave a Reply

Your email address will not be published. Required fields are marked *