Wednesday, June 15, 2005
Thursday, June 09, 2005
Is Inheritance Bad?
I hear many voices claiming that Inheritance is bad and recommending to use Composition instead. Their arguments have sense - I saw many examples on how to incorrectly use inheritance.
I would argue on one argument which implicates a tight coupling between a parent and extending class. Let's take classic Vehicle and Car extending Vehicle example. Can we say Car is close coupled with Vehicle? No, because Car is a Vehicle!
What do you think?
I would argue on one argument which implicates a tight coupling between a parent and extending class. Let's take classic Vehicle and Car extending Vehicle example. Can we say Car is close coupled with Vehicle? No, because Car is a Vehicle!
What do you think?
Thursday, June 02, 2005
No More DTO
I just found Mr. Piirainen's thoughts on DTOs and it was enough for me to start writing something right now.
When people talk about "transfer" and that they need some object (assuming DTO) to do a "data transfer" I would review the need for this transfer.
DTO is very similar to Memento design pattern so DTO could be called a variation of it. Memento could be useful for saving state of some object. We create Memento if we need some kind of client-side caching where we store a local state of server-side object. See a discusion regarding DTO and caching in comments below.
But when somebody talks about the need to "transfer" some data I would suggest to get the data directly from the source! Distinquish "transfer data" and "store state". No need for a transfer - just let an object that needs the data talk to object which is responsible for holding the data. Find object who demands the data. Find object which holds the data. While in your demanding object, get the data from the direct source. This is so easy.
When people talk about "transfer" and that they need some object (assuming DTO) to do a "data transfer" I would review the need for this transfer.
DTO is very similar to Memento design pattern so DTO could be called a variation of it. Memento could be useful for saving state of some object. We create Memento if we need some kind of client-side caching where we store a local state of server-side object. See a discusion regarding DTO and caching in comments below.
But when somebody talks about the need to "transfer" some data I would suggest to get the data directly from the source! Distinquish "transfer data" and "store state". No need for a transfer - just let an object that needs the data talk to object which is responsible for holding the data. Find object who demands the data. Find object which holds the data. While in your demanding object, get the data from the direct source. This is so easy.