wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Implements DBAcess - URLyBird 1.2.3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Implements DBAcess - URLyBird 1.2.3" Watch "Implements DBAcess - URLyBird 1.2.3" New topic
Author

Implements DBAcess - URLyBird 1.2.3

Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi for jRanchers

So I'm doing URLyBird 1.2.3 and I've learned on this forum a lot...thank for all !!
My question is:
I received from SUN assignament DBAcess interface...and I've read here that most pleople has use Facade or Adapter pattern to implement this concrete class. I read that Denis DVD in Andrew's book had use to (facade). But this no make sense for me !!! Facade dont fit in this designer situation because many issues....(I wont describe here about theses patters)....but they dont fit completely...I mean...why they use facade if we dont wanna hide some sub-system (this is a main reason to use facade patterns) ?? Maybe jut to say that they have use "some patters in assignment"....
Another questions is...I've seem that some people create 2, 3 classes to implement this situation - one deal with "file acess" stuff and another to deal with "look" stuff ? Why ?
File acess you can use RandomAccessFile agregation and lock you use ReadWriteLock or syncronized methods !!! It's not make sense for me to create anothers classes and delegating this controls outside !!! I know and I agree with "each class have to deal with one responsabilty".....but this not a case...
Why dont create simple only class that implement DBAcess and dealing with file acess using RandomAccessFile and lock with ReadWriteLock ? This is dont OOP programmer ? using agregations stuff ?
Give your opinions rancherssss.....
Regards.

Fernando Franzini - Java Blog
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 67
Hi Fernando!

I'm working on B&S Project, but i think not mutch diferent... Facade pattern is because in the future the system will be run on the web (B&S) and in this case (when this happens) the only thing that you need is show the Facade to Delegate from web tier. In other words you can change Swing view to Web View easily.

Sorry about my english!


Julio Cesar Lopes Marques
Sun Certified Java Developer 5, Sun Certified Java Programmer 5
Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 232
Julio Cesar Marques wrote:Hi Fernando!

I'm working on B&S Project, but i think not mutch diferent... Facade pattern is because in the future the system will be run on the web (B&S) and in this case (when this happens) the only thing that you need is show the Facade to Delegate from web tier. In other words you can change Swing view to Web View easily.

Sorry about my english!


Exactly:

  • reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system;


  • source: http://en.wikipedia.org/wiki/Facade_pattern


    SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    HI dudes....

    That is I'm talk about !!! This thinks is wrong !!! The view layer will acess server layer by interface using polimorfism !!! We dont need FACADE PATTERNS to isolate view layer to database !!! It's already are cause of polmorfism !!
    In my understanding..the facade patterns have the main motivation to HIDE COMPLEX SUBSYSTEM AND MAKE THEM EASILY TO USE !!! So....where inside the server layer I have to use another complex API ? or wanna hide somenthing ? Look.......the people are using one patter with a wrong motivation !! Look at facade patterns dont tell that you should use polimorfs bahaviors...you can build facade withoud interfaces.....

    Hey Jari !! Did you see the wiki simples ? CPU, MEMORY, HardDrive and Computer class ? So tell me...where the server layer fit ?
    Julio Cesar Marques
    Ranch Hand

    Joined: Mar 21, 2009
    Posts: 67
    Hi Fernando!

    Using polimorphism you will expose your DBAccess to client layer. What happens for example is if the data source change for a database and no more .db file? Client layer must be change. But, if client Layer is looking at a Facade, they don't care with wich are behind of Facade.

    Cheers!
    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2266
        
        3

    Hey, Fernando.

    Particularly, my approach was that I only have one Data class that deals with all database-related matters (such as dealing with the RandomAccessFile object, locking mechanism, etc). One thing that I see quite oftenly is people using the wrong words to describe a feature or a behavior (for instance, some people say "tier" when they mean "layer"); maybe it wasn't exactly what people meant by saying "facade". If you think that only the Data class can do the job, go right ahead. One thing to remember is that, in this certification, oftenly you have more than one option to take; take your time to think what is the best choice and go for it, always remembering to keep things as simple as possible.


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

    Joined: Mar 21, 2009
    Posts: 67
    Is truth! You are free to choose your way. And remember keep things as simple as possible.
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    Using polimorphism you will expose your DBAccess to client layer. What happens for example is if the data source change for a database and no more .db file? Client layer must be change. But, if client Layer is looking at a Facade, they don't care with wich are behind of Facade.


    If you database paradigm change....remenber that another layers are using polimorfs referente to the DBAcess interface !! You just need implement another brand of layer folowing the DBAcess interface contract !!! Nothing is gonna happing or change with another layers/tiers whaterver is remote or not.....And what about FACADE ? Facade patterns isnt used to have this flexibility !!! As I say before.....You shouldnt implements a pattern where this this pattern dont fit !!!
    Vasya Pupkin
    Ranch Hand

    Joined: Dec 06, 2006
    Posts: 39
    Fernando, I agree with you on that one. Facade is an overkill for this application, but it will become important at the time you want to expand your application.
    Although, I have this extra layer of complexity in my code, because my design looked immature without it.


    SCJP, SCJD
    Jari Timonen
    Ranch Hand

    Joined: Jan 16, 2004
    Posts: 232
    Hi,

    It's your software - design as you wish Just remember to add your design points to your choises.txt


    1. I really want to hide my sub-system. GUI does not have to know that it has two different connections implementations. I do not want to expose my DBAccess(even being one common) iterface to GUI.(What if it changes?) (this is the main reason for facade in this situation). (behind connections there is only one implementation of DB logic)

    2. Think of a situation where you have to change your GUI. Maybe with web techniques. If you don't have isolating layer (facade), you have to make lot's of copy-pasting instead of writing a single method call.

    Quick example:

    Without facade:



    With facade:


    Have a look at Core J2EE Patterns: Session Facade



    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5407
        
      13

    I also did everything in 1 class (like Roberto), so Data class takes care of the access to database file (used a record cache btw, so file access limited to start and end of the app) and the locking/unlocking of a record.

    In my opinion using a facade in your Data class has no effect when you switch from a gui representation to a web representation. The only thing it facilitates is the adding of an other database system (instead of a database file a RDBMS is used as database). That's one advantage of the data class would be a facade (your locking code will not change and you don't have to reimplement it).
    And i think this was the original discussion started in this topic.

    Then Jari mentioned in his quick example a facade on a different level and a completely other discussion: should you expose your dbaccess methods to the client or not. This forum has an extensive thread discussion (initiated by Andrew Monkhouse by the way), you can find it here.

    Here i used a business layer service which exposes only 2 methods to the client. The business layer service implementation calls the methods (lock, update, unlock) of the data class (and also does some business checks) and hides all steps necessary to book a contractor/room and from the gui just 1 simple/easy method call has to be done

    in conclusion it is like it's already said by some people: think about all the alternatives, convince yourself which one is the best (according to your arguments), implement that one and argument your decision in choices.txt (like you have another 150 decisions to make and to argument )

    Good luck!
    Kind regards,
    Roel


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

    Joined: Jan 16, 2004
    Posts: 232
    good points Roel.
    Good luck!
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    Hi Jari Timonen

    I Agree with you.....but you are talking about make some Facade layer (service ou bussines whatever you wanna call) above data layer !!
    Look at layers dependences: GUI->ServiceFacade->Persistence->FileData....as Roel De Nijs said....
    And what i'm talk about is this post is build facade INSIDE of a classe that implements DBAcess interface.

    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2266
        
        3

    Calm down guys, let's try to continue the discussion smoothly...
    Julio Cesar Marques
    Ranch Hand

    Joined: Mar 21, 2009
    Posts: 67
    Uma coisa é uma coisa e outra coisa é Outra coisa!
    (One thing is one thing, other thing is Other thing) lolololololol
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11481
        
      94

    Thanks Roberto for trying to keep this discussion calm.

    Fernando - have you read chapter 5 of SCJD Exam with J2SE 5, particular around page 134 where we discuss why we chose to implement our DvdDatabase class as a Façade? Perhaps that section may help you understand our reasoning.

    You are correct that a Façade is not required here - in fact the FAQ for chapter 5 around page 161 explicitly states "There are no specific patterns that must be used within your submission; you are free to use any that you feel fit your requirements.". If a Façade does not suit your requirements then don't use it. You will not gain points for using a Façade, nor will you loose points for not using a Façade. However it is possible that using a Façade (and acknowledging it) might help in general coding considerations if it makes your code easier to understand.


    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    K. Tsang
    Bartender

    Joined: Sep 13, 2007
    Posts: 2524
        
        8

    Wow what a discussion. Anyway the ultimate thing is not what design patterns you use but how you approach it. Whatever you have done may or may not be the facade design pattern or any other design patterns. For me personally, after I implemented all that DB access stuff, I didn't even know if I use design patterns, if I did, I didn't know what the name is.

    When design the DB access, think from the client side. Do you want to expose lock/unlock methods? How the client determine which database to connect ("local" or "remote")? How many exceptions do you want your client code to catch? All these impact your design one way or another.

    Hope this helps.


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

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    Hey ranchers......Thanks for replys....as I said before...I've learned a lot here !!!
    Regards and see you around
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    Hi ranchers...
    I would like to apoligize cause I realized that I was ofensive or rude in some replys.....and I didnt mean ...neverrr !!!
    So...I realy realy sorry for all ranchers that help me here....
    I would like to say that english is my second language and I'm still learning...and it's very dificult exanchange informations about this abstract issues....
    I'm really aprecciate stay here with all of you....and I've learned a lot !! So i'm really sorry.
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    Fernando, Personally, I didn't take it that way, and was wondering why anybody else did. Most likely it is because you used Bold text, and it may have appeared that you were shouting. I'm almost certain that was the problem. It is like using all upper case letters. That is considered shouting and rude in a forum environment. Hope this helps in the future!


    SCJP, SCJD
    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2266
        
        3

    Anne Crace wrote:Most likely it is because you used Bold text, and it may have appeared that you were shouting. I'm almost certain that was the problem. It is like using all upper case letters. That is considered shouting and rude in a forum environment. Hope this helps in the future!


    Very well pointed out! Thanks, Anne!

    Anyway Fernando, this was a nobel gesture, and it is notable that you are a very kind person. But I'm not surprised; after all, you're brazilian!!!
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    Hi for all

    I really didn't know all this details about BOLD and UPPER CASE text !!! But thanks for tips....
    I'm really sorry...
    See you around.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: Implements DBAcess - URLyBird 1.2.3