The Artima Developer Community
Sponsored Link

Design Forum
Containment vs Inheritance

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
John Pelly

Posts: 1
Nickname: jpelz
Registered: Jul, 2003

Containment vs Inheritance Posted: Jul 1, 2003 5:33 PM
Reply to this message Reply
Advertisement
I have a simple question, which has hopefully a simple answer. I'm sure this has been hashed before, but I'd like to get the opinion of people in this forum...

I have certain abstractions in my system, which may or may not be persisted. If the entity is persisted, it may be referenced/"looked up" by a primary key. (Obvious scenario is database).

So, I'm pretty confident that I don't want the "core" entity object to contain a notion of a "primary key" since it doesn't make sense if the object is not persisted. The question is, what are the tradeoffs in using inheritance vs containment for the persisted entity?

Here's a simple example of the two paradigms:

// Containment
interface Entity {
  public Object getData();
}
 
interface PersistedEntity {
  public PersistedEntityPK getPK();
 
  // must call getEntity() method to call any of Entity's members...
  public Entity getEntity();
}
 
 
// Inheritance
interface Entity {
  public Object getData();
}
 
interface PersistedEntity extends Entity {
  public PersistedEntityPK getPK();
  // all other Entity methods inherited from super interface
}


It seems to me like inheritance might be the way to go, if nothing else for the substitution argument. Any thoughts for/against?

Thanks
John

Topic: Can anyone help me on pseudocode? Previous Topic   Next Topic Topic: Java Persistence from a (RDBMS) legacy perspective

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use