File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes extension or logical composite design which one is better Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "extension or logical composite design which one is better" Watch "extension or logical composite design which one is better" New topic

extension or logical composite design which one is better

Tanu Gulati
Ranch Hand

Joined: Oct 06, 2008
Posts: 113

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.

Tanu Gulati

Tanu Gulati
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
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

JDBCSupport - An easy to use, light-weight JDBC framework -
I agree. Here's the link:
subject: extension or logical composite design which one is better
It's not a secret anymore!