• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

extension or logical composite design which one is better

 
Ranch Hand
Posts: 113
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic