This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes About design pattern used in SCJD 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 "About design pattern used in SCJD" Watch "About design pattern used in SCJD" New topic
Author

About design pattern used in SCJD

Jamy Wang
Ranch Hand

Joined: Sep 21, 2003
Posts: 83
Which design patters is ussally used in the assignment of SCJD?
mvc ----- in GUI desing?
adpter ------ db?
Why and How to use those design pattern in our design in the assignment?
Where I can find some good tutorials and examples?
Thank you for your reply!


Best Regards<br /> <br />SCJP1.4 SCJD1.4 SCEA
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi James,
Here are two links I found useful as far as design patterns are concerned :
Design Patterns in Java
The Design Patterns Java Companion (by James W. Cooper)
Best,
Phil.
PS: Could you please shorten your name ? It unnecessarily takes two lines in the threads list... You can do that here. Thanks.
[ September 22, 2003: Message edited by: Philippe Maquet ]
Jamy Wang
Ranch Hand

Joined: Sep 21, 2003
Posts: 83
Thank you,Philippe .
Could you give me some examples of design patters used in SCJD?
How can I design a good project for SCJD assignment?
Which design patterns are usually used?
I'll be very thankful if anyone who would like to guide me.:-)
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi James,
I am not a design patterns specialist and Andrew probably would be of better help, but here are the most used of them in the SCJD assignments :
Adapter or Fa�ade to abstract data access (you hide the technical database details to the client, only showing an interface which makes more sense to it (like book() and search()).
Factory, to help you to instantiate the right classes depending on the mode flag (network client or stand-alone client)
MVC (Model/View/Controler) for the gui part, as Swing makes extensive use of it.
Remember that design patterns are there to help you build a better design, and to help you communicate it to other people. There are not there to confuse you.
Best,
Phil.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11277
    
  59

Hi James,
Welcome to JavaRanch.
It is best learn the design patterns, then as you work on projects, determine which ones meet your requirements. Telling you which patterns I used for my assignment is not very helpful: they may not fit your requirements, trying to work out how I used a particular pattern may confuse you, or worse - you could try to force your application to use a pattern even though it is not a good fit.
If you would like a list of patterns that are commonly used, you might want to look at this thread
It is good to use a design pattern where it fits the requirements. But it is not essential for this assignment.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jamy Wang
Ranch Hand

Joined: Sep 21, 2003
Posts: 83
Thank you all .JavaRanch is a good place.
I still have some questions about design pattern...
1)How could I find the patterns fit my design? Are there any skills when doing that?
2)How to realize the patterns in my design? For example, how to use mvc pattern design the GUI, how to use adpter pattern for DB part?I'm eager to get some examples for that.
Thank you in advance!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11277
    
  59

Hi James,
How could I find the patterns fit my design?

You have to read and understand what the patterns are trying to achieve. What is the motivation for the pattern. What is the applicability of the pattern. What are the consequences of the pattern.
When you have done that, then as you design software you will recognise areas where what you are trying to do fits in with a pattern you have learnt.
How to realize the patterns in my design?

Every book I have read on design patterns gives an example of how to realise the pattern. Philippe has given you a couple of good links to some online books that you can read. Another book you can download (although it is not yet complete) is Bruce Eckel's Thinking In Patterns which also has a lot of Java samples.
Eugene Kononov provided a good example of an MVC design in this thread.
Regards, Andrew
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Andrew,
I discovered patterns for the first time when I discovered java in spring of this year. I now recognize the main of them as far as I don't work in the GUI area. Except for MVC (by the way Eugene's example and explanations are amazingly clear, thank you), I cannot name my GUI designs.
Here is an example where you may help me.
In my server GUI, under a main tab "Settings", I have three sub-tabs called "Application", "Database" and "Network". Server-side contents of suncertify.properties is managed from those tabs.
Each of them has a panel on the left side which contains one control per property, and a panel on the right side which contains three buttons : "Save" (saves changes to the file), "Cancel" (cancels changes by reloading from file) and "Reset" (resets all properties to their default values).
After having built the first settings panel, I wanted to reuse the buttons panel for the two next ones. What I did is this :
I defined an interface to be implemented by the left-side settings panels :

and an interface to be implemented by the buttons-panel :

The buttons panel, which is an instance of this class :

receives a link to the settings panel it controls by a call to its method :

Any settings panel extends :

which receives a PropertyFile and a SettingsController in its constructor.
Now each button of SettingsControllerPanel (the buttons panel) may perform its job in an abstract way, simply by calling the save(), cancel() and reset() methods of its SettingsActions. And its setChanged() method can enable/disable the buttons according to the current "changed" state.
Well, as far as design patterns are concerned, my problem is that I cannot name that design. I'd like to because designs are far easier to explain when you can name them (after all it's one of the two contributions of design patterns : help in design and help in design communication).
For me, what I did there is just a trick, not (a) well-known pattern(s).
Can you name it Andrew ? (and BTW tell me if the design seems good to you ?)
Mmh, I am afraid you'll reply something like : "Nice Phil ! It's a very good example of the Trick pattern !"
Best,
Phil.
[ September 23, 2003: Message edited by: Philippe Maquet ]
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Andrew,
A few more words to explain why I am confused : if I try to explain that design with MVC, it gives something like this :
AbstractSettingsPanel (and descendants) is a VIEW whose MODEL is its PropertiesFile (BTW, the latter is a "Fa�ade" which simplifies access to Properties a bit like an Adapter (all methods I don't use are hidden) and offers a hidden link with a File instance).
But AbstractSettingsPanel is partly its own CONTROLLER too (it listens for changes in individual controls to be able to call its SettingsController.setChanged() method.
Now SettingsControllerPanel (the buttons panel) is partly a CONTROLLER of AbstractSettingsPanel (user clicks on its buttons fire an action in its SettingsActions), is also a VIEW (it's a panel of buttons) and owns its own MODEL (the "changed" state).
Is that MVC ?! Or just a messy one ?
Best,
Phil.
[ September 23, 2003: Message edited by: Philippe Maquet ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11277
    
  59

Hi Philippe,
Nice Phil ! It's a very good example of the Trick pattern

Seriously, I think this is pretty close to the Mediator design pattern.
BTW tell me if the design seems good to you


I discovered patterns ... in spring of this year

Mmmm, spring. We are now into the third week of spring, and temperatures are in the very high 20s. Looks like another hot summer I may have to resign as bartender so I get more time on the beach
Regards, Andrew
[ September 23, 2003: Message edited by: Andrew Monkhouse ]
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Andrew,
Lucky guy who's now in early spring ! I never thought of it before, that big advantage - though quite temporary - to live up side down ...
Seriously, I think this is pretty close to the Mediator design pattern.

I just reviewed the Mediator pattern after your post. I would say it's not Mediator, but it offers similar advantages in terms of collaboration.
Typically, Mediator is a class which helps multiple classes (I suppose more than two) to work together without knowing anything about the other ones (except the mediator). In the case some of those classes change, the mediator is the only class which may need some refactoring.
In my case above, as I have only two collaborating classes, a third SettingsMediator class woulnd't add much in clarity I think. And as both classes know the other one only through an interface, they can evolve without any need to refactor the other as far as the required interface is not changed.
Now if that design is easy to understand, it's probably not a big deal if I cannot name it.
Anyway, thank you for Mediator : I'll add it to my patterns gear.
Regards,
Phil.
PS: How did you insert the first smiley of this post ?! I don't find it in the "Instant Graemlins" section.
OK, I found the image in the HTML sources : . But is there a shortcut ? I love it !
[ September 23, 2003: Message edited by: Philippe Maquet ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About design pattern used in SCJD
 
Similar Threads
Design Pattern to be used
Got the score report
Design Patterns in my design after refactoring the server side classes, advice needed.
Design Patterns
Representing a singleton in star uml