This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extension or logical composite design which one is better

 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ranchers, i just joined a new project in my company and was looking at the architecture of the project where i noticed some thing and wanted to discuss with some questions at the end.

we have some staandard tables in data bases and corresponding java objects , for ex. policy table in database and policy object (java class named policy) and as most of the designs policy object is having gettter and setter method for all the fields we have in policy table. the database table and objects are standard and we can not modify them

we have created a database table called PolicyExtension where we can add fields as per our requirements, basically what i mean to say is , since we can not add in to policy table we are adding in to PolicyExtension similary we have a class PolicyExtension where we can add the getter setter method for PolicyExtension table.

NOW THE REAL QUESTION .... when i saw PolicyExtension class i was expecting it to be inheriting Policy class but it is not inherting

when i try to contact the Architect the answer that i got was .... "our pattern treats Java extension objects as a piece of a logical composite rather than as a specialization"


what i understood from this line is ....we are actually creating an object of Policy inside policyExtension class and using it but what i did not understand was why do we need to do this and what are the advantages of this kind of design and how it is better ?

i tried to describe my scenario as better as i can be please let me know if i can still improve it.


thanks
Tanu Gulati


 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a design principle that says 'Favor composition over inheritance'.

Composing decreases coupling between two classes, therefore the project architect might have chosen it.

Also check http://www.artima.com/lejava/articles/designprinciples4.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic