• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loosing Object-Oriented Design points - URLyBird

 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9790
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel
Thanks for tips....I'm thinking about....and....I'll make my decisions.
Regards.
 
Ulises Pulido
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Roel De Nijs
Sheriff
Posts: 9790
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9790
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 223
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    # 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
    Posts: 3348
    12
    Android Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Fernando Franzini
    Ranch Hand
    Posts: 489
    2
    Java Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 3348
    12
    Android Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 9790
    101
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 9790
    101
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 489
    2
    Java Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 9790
    101
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 489
    2
    Java Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 9790
    101
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic