OOP-Encapsulation issues

Published 11-08-2005 11:14 PM | jokiz

As I was refactoring some of our codes, what struck me was the idea of object oriented programming particularly encapsulation.

For example, we have this Customer object which is distinct with its CustomerID property.  We needed to have versioning for the said entity and so we introduced an additional Version integer property.  I've been seeing routines throwing CustomerID alongside Version to refer to a particular Customer object.  Ideally (from what I know), the said routines should be just interacting with an instance of Customer object in the first place.  The versioning should have been implemented internally through encapsulation and calling routines should be unaware about versioning which should've been handled by the Cutomer class himself.

I hate to see codes throwing and consuming PK's of business entities as parameters and not instances of business entities.  Anyone who wants to shed a light on these?  Am I on the right track?

Filed under: , ,

Comments

# dehran ph said on November 9, 2005 2:26 AM:

like this?
public int DeleteCustomer(int customerId){

}

instead of
public int DeleteCustomer(Customer customer){

}

now you'll hate me, hehe...

# jokiz's blog said on November 9, 2005 8:26 AM:

In response to dehranph's comment on my previous post (http://community.devpinoy.org/blogs/joeycalisay/archive/2005/11/08/401.aspx),...

# jokiz's blog said on August 11, 2006 4:42 AM:

In response to dehranph's comment on my previous post (http://community.devpinoy.org/blogs/joeycalisay/archive/2005/11/08/401.aspx),

# jokiz said on March 30, 2007 3:08 AM:

i once joined a team in developing a procurement/bidding system in ASP.NET. it involved "project for

# Joku said on May 1, 2007 12:11 PM:

I feel the same way about passing the IDs around. Those tie IDs are specific to the database and tie you to the database. You should just be passing around business objects... but it doesn't look like that's a common practice in ASP.NET

# mininkperi said on December 10, 2007 11:29 AM:

Am I on the right track?