This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Object Model vs Data Model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Object Model vs Data Model" Watch "Object Model vs Data Model" New topic
Author

Object Model vs Data Model

anuj bhatnagar
Ranch Hand

Joined: Aug 06, 2007
Posts: 31
a


thanks & regards,<br />Anuj Bhatnagar
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2229
    
    7

anuj bhatnagar wrote:Table - Business_Info (id,name,code,type,parentId)

Class Business which has the similar fields as in Business_Info table but the objects of Business can be logically be of three types Enterprise, Division or an Originator from the logical point which is determined by parentId field.


You mentioned "types" enterprise, division, originator. Then a Enum can be a viable option. Not knowing exactly your requirements and how "similar" will say EnterpriseBusiness class be with Business_Info class. Also rather than an abstract class approach, you may want to consider interface approach. The classic abstract class vs interface issue.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
anuj bhatnagar
Ranch Hand

Joined: Aug 06, 2007
Posts: 31
b
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2229
    
    7

I get what you are trying to do. Yet choosing the best approach needs to weigh in the pros and cons.

From your Business_Info table, the "type" field can surely be a constant (Enum). Say the sample data looks like:
id,name,code,type,parentId
1,abc,somecode,business,1
2,pqr,somecode,division,2
3,xyz,somecode,originator,3
4,sub-bus,somecode,business,1
5,sub-div,somecode,division,2
6,sub-org,somecode,originator,3

Then the parentId is simply foreign key to the id field. And in coding, you will then need some sort of Business Delegate object to determine what kind of Business_Info that DB record is and perform the necessary business logic for that particular type.
anuj bhatnagar
Ranch Hand

Joined: Aug 06, 2007
Posts: 31
Yes that makes sense but how about adding a new business type into the system. Wouldn't it require Enum change?
And how do we handle a case when one of the Business Type require one extra field?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2229
    
    7

anuj bhatnagar wrote:Yes that makes sense but how about adding a new business type into the system. Wouldn't it require Enum change?
And how do we handle a case when one of the Business Type require one extra field?


You can have another table storing such constant then use a POJO to retrieve it rather than so-called hard-coding in code.
anuj bhatnagar
Ranch Hand

Joined: Aug 06, 2007
Posts: 31
K. Tsang wrote:
anuj bhatnagar wrote:Yes that makes sense but how about adding a new business type into the system. Wouldn't it require Enum change?
And how do we handle a case when one of the Business Type require one extra field?


You can have another table storing such constant then use a POJO to retrieve it rather than so-called hard-coding in code.


Oh Ok. Thanks I think I got the answer if what I was looking for.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Object Model vs Data Model
 
Similar Threads
Need Clear Struts Navigation Flow
Difference between skeleton and model service
Create a type for every reasonable domain concept?
Can anyone please explain Entity Inheritance and Polymorphism in simple words
use OOP to design database tables schema?