• Post Reply Bookmark Topic Watch Topic
  • New Topic

value object containing logic  RSS feed

 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
if my data comes in tab seperated form(like tajamitpk) from database and i have to cut these data using string tokenizer so that i can pass them in value object constructor to populate value object. If i put this parsing logic in value object itself as a method which in turn calls constructor to populate value object.
Is this approach is good design with respect to value object
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on how you use the Value Object.
If you use it as a Data Transfer Object, it might be a bad idea, because it would have to exist (for example) on both the client- and server-side, but the parsing only happens on the server. That is, if the parsing changes, technically the client is affected, although logically, it wouldn't have to.
Does that compute?
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If value object contains parsing logic or any other logic and method.Does more methods make it heavy to travel between tiers of the application.
Will it occupy more network space while travelling.
plz clarify
thanks
candy
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If value object contains parsing logic or any other logic and method.Does more methods make it heavy to travel between tiers of the application.
Will it occupy more network space while travelling.

No. It is only the data which will be transfered and not the class.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would separate the parsing logic from the data object.
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would u prefer to seperate parsing logic from data object
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will this design can create problem if yes then how
plz explain
thanks
candy
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by candy varma:
Why would u prefer to seperate parsing logic from data object

I feel that the object's responsibility is to hold data. If in future data comes in a different format, dont you need to change the code?
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If in future data comes in different format, then i can change that method or can add new method.I want to put this method in value object because only that format will populate the particular value object.So the logic should be with the value object itself
what is ur view
thanks
candy
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If in future data comes in different format, then i can change that method or can add new method

Well, if this object has many clients there is problem isn't (Ilja has already mentioned it)?
[ April 21, 2004: Message edited by: Pradeep Bhat ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by candy varma:
If value object contains parsing logic or any other logic and method.Does more methods make it heavy to travel between tiers of the application.
Will it occupy more network space while travelling.

No. But you might need to recompile, retest and redistribute the client when the parsing logic changes, because the client depends on the Data Transfer Object. If the parsing logic is implemented outside the DTO, the client wouldn't be affected at all.
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No dont u think its the object's responsibility to populate itself or contain logic realted to itself as per oo programming concept.
THanks
candy
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This depends on how your define the responsbility of an object.
Consider the following case:
I have an Transfer Object (TO), formerly known as Value Object, which represents a table inside a Database. I have a system, that retrieve the data from DB, store in the TO and sends to the front end for display.
So, the question is: where should I create the SQL statement?
1. in the data access object (DAO) OR
2. in the TO itself?
Both are possible, according to your OO definition. Since the TO knows all its attributes, and thus, it is in fact more easier (just loop all the attributes) to create the SQL, say TO.getSQL(), and then return the SQL to DAO for DB query. However, does this be the responsibilty of DAO? Since DAO is the object that knows the DB well.
Consider, if the DB changes from Oracle to DB2, the SQL may then be different, the aim of DAO is to avoid changes in both front end and back end due to data access. If the SQL generation stays in TO, the TO will change.
Thus, IMO, TO should not contain any logic, especially platform dependent logic.
Nick
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by candy varma:
No dont u think its the object's responsibility to populate itself or contain logic realted to itself as per oo programming concept.

OOP is a tool for managing dependencies. Most often we prefer to put behaviour into the same object as the data it operates on, because it makes the dependency between the data and behabiour easier to manage.
But that force is not the only one. There can be other forces - such as not wanting to have the client affected by changes to the parsing - which can drive us to separate data and behaviour from another.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!