wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Loosing Object-Oriented Design points - URLyBird Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Loosing Object-Oriented Design points - URLyBird" Watch "Loosing Object-Oriented Design points - URLyBird" New topic
Author

Loosing Object-Oriented Design points - URLyBird

Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi folks

I decided to put a bussines layer between data and view. So...view layer will deal with POJO object instead String[]. My question is:
Will I loose Object-Oriented points if I implement my pojo attributes as String ? I know that OOP guideline show that objetcs atributtes have to be meaning and your own types......but in assignment I wont use it !! I'll just get customer ID to book a room !!!
so...

Fernando Franzini - Java Blog
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Hum... I myself created a Room object, with fields that were of each particular type. For instance (I don't have my code here with me), it had int, Date, String... maybe you could lose a few points in the General Considerations criteria because of that... maybe...


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

Joined: Jan 09, 2009
Posts: 486
    
    2

URLbird will be Date, int, BigDecimal or double....
I'm realy think about it.....but I'll implement convertions unnecessarily.......dont you think ?
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi jRanchers

I've decided to build my POJO with typed attributtes and make the proper appropriate convertions. Here is some part ogf my Room class:

/**
* Stores room id.
*/
private Long id;

/**
* Stores hotel name.
*/
private String hotel;

/**
* Stores location for the hotel.
*/
private String city;

/**
* Stores maximum number of people permitted, not includind infants.
*/
private Byte occupancy;

/**
* Stores an enum indicanting if smoking is permitted or not.
*/
private Smoker smoking;

/**
* Stores rate per night.
*/
private BigDecimal rate;

/**
* Store the data of the single night.
*/
private Date date;

/**
* Store customer inumber.
*/
private Integer owner;


If someone have some opinion or diferente ideia....will be welcome...
Regardsss
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5133
    
  12

Hi Fernando,

I think using an Integer for the customer-id is not a good idea, because you will have to check if it's containing 8 digits. So you will have something like so your owner could be a String from the beginning (but that's my opinion).

I also didn't use a seperate enum (I guess) for the smoking-attribute, just a simple Boolean. Besides the id and the occupancy (both Integers) I only used Strings

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi Roel
Thanks for tips....I'm thinking about....and....I'll make my decisions.
Regards.
Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
mm... about the owner id, does it has to be 8 numbers long ? I mean is that needed ?

for instance does the owner id could not be less than 8 digits characters long ?


SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCJD, SCEA in progress
www.ulisespulido.com
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5133
    
  12

Ulises Pulido wrote:mm... about the owner id, does it has to be 8 numbers long ? I mean is that needed ?

for instance does the owner id could not be less than 8 digits characters long ?


If I check the database schema part of my assignment, I read the following:
The id value (an 8 digit number) of the customer who has booked this.


So my interpretation is that this value contains 8 digits, not 7, not 9, exactly 8. But that's just my interpretation of course

Kind regards,
Roel
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
My POJO is all Strings except record number, and that one, I added to make the table more appropriate to view. I use wrapper classes to convert between numeric values and String when needed.


SCJP, SCJD
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
ULises:
I think Roel is right about the 8 digit thing. I used a Mask Formatter. They can't input non digits except backspace and delete, and it won't allow any more than 8 digits. I do validation on the less than 8 instance and flip a label with an error message on if it doesn't pass.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5133
    
  12

Anne Crace wrote:My POJO is all Strings except record number, and that one, I added to make the table more appropriate to view.


I have 2 remarks:
  • I don't show the record number in my table, because that is not really part of the hotel room. It's just a primary key used in the database layer to uniquely identify a record. It would be a whole other story if the actual room number was used as primary key for example.
  • if you use a Boolean for the smoking property, you'll get even a more appropriate view of your table


  • Kind regards,
    Roel
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    # if you use a Boolean for the smoking property, you'll get even a more appropriate view of your table


    I think I see your point, but I just use what is in the file (view with a hex editor). It has Y and N, so that's what I use
    I don't see this as being something that will cost me points.

    I documented the record number in my choices.txt. I start with 1, not 0, too. I just think showing it makes for a more logical view for the user. Looks more like an Oracle table for example. RecNo actually is part of my DBAccess interface (yours is called DBMain, if I'm correct). I also decided that UrlyBird really has no primary key. The record number is the only logical choice, and since I reuse deleted records in my implementation, that goes right out the window, IMO. There's been lots of arguments and many threads on this one!

    PS: I am currently working on using your Submission Jar test, and fluffing out my ant script, so I am familiar with DBMain as opposed to DBAccess
    Thanks for this, by the way.
    K. Tsang
    Bartender

    Joined: Sep 13, 2007
    Posts: 2242
        
        7

    Hello Fernando,

    I did UB as well and mine like Roberto had a Room class. The only thing I think worth mentioning is the transfer of syncrhonized POJO vs String[]. Since all the data is from the server, that data must to transfered to the client. Now is sending a POJO faster or sending a String array faster? Given a pojo or array per record.

    Another point may be from the maintenance view. Is changing a POJO easier or changing the array? And array depends on how often you use it.


    K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    Hi k.

    I didn't undestand your point. I'm not consider faster stuff cause we all know that with bussines layer and POJO approach is less faster than let GUI layer acess direct persistence layer. Could you clarify your consideration ?
    K. Tsang
    Bartender

    Joined: Sep 13, 2007
    Posts: 2242
        
        7

    Sure Fernando. The point I was trying to make about POJO vs String[] is that the data needs to be transfer over the network through RMI or sockets, assuming your server is on another computer. In fact I don't know if it is faster or not. Transferring a serialized pojo or string array over the network in high quantity (every record in the database file), may impact your application such as loading data to the table, locking delay, who knows.

    I'm not saying either approach is better or even faster. But I'm sure the pojo approach should have more advantages than the string array approach.

    Since array is not considered primitive so I'm sure somewhere there is synchronization of the array before transferring over the network. Hope this clear up your thoughts a bit.

    The other point is maintenance which I'm sure you understand that point.
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5133
        
      12

    K. Tsang wrote:But I'm sure the pojo approach should have more advantages than the string array approach.


    I described this advantages in my choices.txt: less error-prone, your code becomes easier to read,...

    Compare the following statements, all possibilities to access the hotel name (from to ):


    Kind regards,
    Roel
    Ulises Pulido
    Ranch Hand

    Joined: Jul 24, 2008
    Posts: 81
    Anne Crace wrote:ULises:
    I think Roel is right about the 8 digit thing. I used a Mask Formatter. They can't input non digits except backspace and delete, and it won't allow any more than 8 digits. I do validation on the less than 8 instance and flip a label with an error message on if it doesn't pass.


    Ok, I have the same statement as Roel and I agree in that I need to validate that section, I only have this question, will the user be allowed to input "00000001" for instance or does it have to begin with "10000000" ?
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5133
        
      12

    Hi Ulises,

    I allowed anything that's an 8 digit number, so 00000001, 10000000 and 12345678 were all valid entries.

    Kind regards,
    Roel
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    I think Roel is right about the 8 digit thing. I used a Mask Formatter. They can't input non digits except backspace and delete, and it won't allow any more than 8 digits. I do validation on the less than 8 instance and flip a label with an error message on if it doesn't pass.


    In my opinion....independent of the view layer and mask stuff....the validation must be implemented in another place to ensure view layer portability. In my URLyBird architecture, I implemented in bussines layers....in book() method. This mean that you can't wait that field came correctly....
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5133
        
      12

    Hi Fernando,

    Of course you have to do that check in your business layer. But there is no problem in adding some check client-side. If a web-application will be developed instead of the standalone gui there will be a choice: adding a similar check or handling the exception thrown by the business layer.

    But as you said: it's required to validate it in your business layer, a check client-side is optional.

    Kind regards,
    Roel
    Ulises Pulido
    Ranch Hand

    Joined: Jul 24, 2008
    Posts: 81
    From my point of view alerting the user that some input is not the expected by disabling the buttons until the user sets a valid input is a good way to avoid showing the user some "usage errors" that they don't like to see.

    Also I've seen that this is a highly used technique in standalone applications in the industry.

    An example might be eclipse, try to create a project and if you don't specify a name you can't continue and the "next" button is disabled.
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    From my point of view alerting the user that some input is not the expected by disabling the buttons until the user sets a valid input is a good way to avoid showing the user some "usage errors" that they don't like to see.

    You are completely righ Ulises...this made software easy to use etc...etc....but as I said....you still need implement the bussines rules in another right place and don't expected that GUI deal with this rules.....
    Good tips in this post...thanks for all
    Ulises Pulido
    Ranch Hand

    Joined: Jul 24, 2008
    Posts: 81
    Roel De Nijs wrote:Hi Ulises,

    I allowed anything that's an 8 digit number, so 00000001, 10000000 and 12345678 were all valid entries.

    Kind regards,
    Roel


    Ok just to recap, in your text field you allow to the user to specify the number 00000001 as valid but 1 is invalid, because they have to specify 8 digits characters at least?

    Is that correct ?
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5133
        
      12

    Hi Ulises,

    You are right:
    - user can only enter digits in that field
    - user had to enter exactly 8 digits (otherwise he gets a validation error message)
    - user can't enter more than 8 digits

    Kind regards,
    Roel
     
    wood burning stoves
     
    subject: Loosing Object-Oriented Design points - URLyBird
     
    Similar Threads
    Layer over DBAcess - UrlyBird
    Pattern for DOS/console + Entity(ejb3)
    Hibernate transactions
    java program to convert pojo object to pojo xml
    Data Transfer Object + JPA in EJB 3.1 world