aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Room class and conversion methods package location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Room class and conversion methods package location" Watch "Room class and conversion methods package location" New topic
Author

Room class and conversion methods package location

Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hello Everybody,


I moved my Room class out the suncertify.db package where I have my Data class to a suncertify.domain package
where I intend to have all the business logic code.

I wrote a couple of conversion methods:

- Room to String[] and
- String[] to Room

and at the moment they are part of my Room class.

Does this sound like a reasonable approach?
Any pros and cons?


Thanks in advance,


Carlos.


SCSA, OCA, SCJP 5.0, SCJD http://www.linkedin.com/in/carlosamorillo
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4907
    
  10

Hi Carlos,

I created a RoomUtils utility class (in a util package) which has both conversion methods and a whole lot other utility methods (e.g. see if a room is booked, filter list of rooms for exact matches,...).

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Howdy, Carlos!

Does this sound like a reasonable approach?


Champion, I'd say that, even it the Room class is indeed a domain class, it depends on how you are organizing the domain logic. If you are organizing it with Transaction Scripts, then it is better to have a utility class to do that (which is what I did too), so that the Room class will simply be a DTO. If you are organizing it with a Domain Model (which I would not advise for the solution of this problem), then it is better to have these methods in the Room class.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Roberto,


Could you please elaborate a bit further?
I don't quite clearly understand what you are saying.

I do see the Room object as a Value Object.


Thanks,


Carlos.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Howdy, Carlos!

First, here's an interesting text by Martin Fowler about value objects:


You can usually tell them because their notion of equality isn't based on identity, instead two value objects are equal if all their fields are equal. Although all fields are equal, you don't need to compare all fields if a subset is unique - for example currency codes for currency objects are enough to test equality.

Early J2EE literature used the term value object to describe a different notion, what I call a Data Transfer Object. They have since changed their usage and use the term Transfer Object instead.


Transaction scripts is an object-oriented procedural approach. In this case, you'll only have DTOs, which will be responsible for carrying data back and forth between the database all way up to the presentation layer. A DTO usually reflects the same structure as of a database table. For this approach, it is a good idea to have a utility class that transforms Room -> String [] and vice-versa.

On the other hand, if your design is based on a model, and you have MDD, then the entities of your domain will hold the domain logic, and in this case, it would be a good idea to have the logic of Room -> String [] in the Room class. However, it is sort of impossible to see the Room class as an entity (even though it sound like one), because its strucutre do not provide anything that we can see as an identity.

In a nutshell: in a real-world scenario, it would depend on how you are organizing the design of your architecture. For this assignment, you can go for the utility class and you'll do well!
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Roberto,


On the other hand, if your design is based on a model, and you have MDD,


What does MDD stand for?

Thanks,


Carlos.
Andriy Pererva
Ranch Hand

Joined: Jul 19, 2009
Posts: 73

What does MDD stand for?


Model-Driven Design


SCJP 6.0(95%), SCWCD 5(94%), SCJD (working on B&S v.2.3.1)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Room class and conversion methods package location
 
Similar Threads
URLyBird Thoughts about design and loosely coupling between Data and Room classes, etc.
Extending Sun interface
Placing interfaces and respective implementations in seperate packages
Constructor Issue
Looking for some nice advice