• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Implements DBAcess - URLyBird 1.2.3

 
Ranch Hand
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 80
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
     
    Fernando Franzini
    Ranch Hand
    Posts: 497
    2
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 80
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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!
     
    Bartender
    Posts: 2292
    3
    Eclipse IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Julio Cesar Marques
    Ranch Hand
    Posts: 80
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Is truth! You are free to choose your way. And remember keep things as simple as possible.
     
    Fernando Franzini
    Ranch Hand
    Posts: 497
    2
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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 !!!
     
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Jari Timonen
    Ranch Hand
    Posts: 232
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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



     
    Sheriff
    Posts: 11604
    178
    Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Jari Timonen
    Ranch Hand
    Posts: 232
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    good points Roel.
    Good luck!
     
    Fernando Franzini
    Ranch Hand
    Posts: 497
    2
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 2292
    3
    Eclipse IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Calm down guys, let's try to continue the discussion smoothly...
     
    Julio Cesar Marques
    Ranch Hand
    Posts: 80
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Uma coisa é uma coisa e outra coisa é Outra coisa!
    (One thing is one thing, other thing is Other thing) lolololololol
     
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Bartender
    Posts: 3648
    16
    Android Mac OS X Firefox Browser Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Fernando Franzini
    Ranch Hand
    Posts: 497
    2
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hey ranchers......Thanks for replys....as I said before...I've learned a lot here !!!
    Regards and see you around
     
    Fernando Franzini
    Ranch Hand
    Posts: 497
    2
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Ranch Hand
    Posts: 223
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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!
     
    Roberto Perillo
    Bartender
    Posts: 2292
    3
    Eclipse IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 497
    2
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic