wood burning stoves*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Design Patterns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Design Patterns" Watch "Design Patterns" New topic
Author

Design Patterns

Dhandapani Venkataraman
Greenhorn

Joined: Nov 30, 2003
Posts: 10
I have to design a class that has to run on the caller's thread and should also have some business intelligence built in that.Am using jdk 1.1 as it is what is right now supported by the environment that I work. The class that I have to design should be modal in function. The UI part however is decoupled from the class.The class will accept a pin and check for the validity for the pin or update a changed pin or store a new pin. I would like to know if there are any design patterns that are available for this scenario.

Thanks in advance.
raphael Bereh
Ranch Hand

Joined: Jan 15, 2002
Posts: 79
Bill Venners: Is the value of patterns, then, that in the real world when I feel a particular kind of pain I'll be able to reach for a known solution?

Erich Gamma: This is definitely the way I'd recommend that people use patterns. Do not start immediately throwing patterns into a design, but use them as you go and understand more of the problem. Because of this I really like to use patterns after the fact, refactoring to patterns. One comment I saw in a news group just after patterns started to become more popular was someone claiming that in a particular program they tried to use all 23 GoF patterns. They said they had failed, because they were only able to use 20. They hoped the client would call them again to come back again so maybe they could squeeze in the other 3.

Trying to use all the patterns is a bad thing, because you will end up with synthetic designs´┐Żspeculative designs that have flexibility that no one needs. These days software is too complex. We can't afford to speculate what else it should do. We need to really focus on what it needs. That's why I like refactoring to patterns. People should learn that when they have a particular kind of problem or code smell, as people call it these days, they can go to their patterns toolbox to find a solution.



How to Use Design Patterns,A Conversation with Erich Gamma ..

This article is very instructive about the use of patterns : Use them to solve a problem when refactoring your code.

So the best way to find the pattern to apply is knowing to problem you are facing. So what is the exact problem ?


SCJP,SCJD,SCBCD
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by raphael Bereh:

Use them to solve a problem when refactoring your code.


Good point! See also http://faq.javaranch.com/view?WhenToApplyDesignPatterns


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by raphael Bereh:

How to Use Design Patterns,A Conversation with Erich Gamma ..

This article is very instructive about the use of patterns : Use them to solve a problem when refactoring your code.


Very good article - thanks for the pointer!
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
So, you are writing a business object. A good design principle is to disassociate your business object from the client, so it matters not the slightest whether that client is a browser, servlet, Struts Action class, Swing class, EJB or whatever. The business delegate pattern is used in this scenario.

Your business object has to access some persistant store, perhaps a file or a database. The implementation of that store should be transparent to the business object, so the Data Access Object pattern can be used.

In summary, your design can look like this.

Client --> Business Delegate --> Business Object --> DAO --> Store

Note that there is not necessarily one right solution, but I believe that you won't be far wrong if you did something as outlined above.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Praveen Balaji
Ranch Hand

Joined: Jun 17, 2001
Posts: 60
This is what I say:

"An intelligent programmer always discovers patterns himself/herself. Eric Gamma should always be a deja vu."
[ June 16, 2005: Message edited by: praveen balaji ]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

This is a great conversation.

I'm going to move it to the OO, Patterns, UML and Refactoring forum so that other people interested in patterns can benefit from it.

So please post your replies there. Thanks!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by praveen balaji:
This is what I say:

"An intelligent programmer always discovers patterns himself/herself. Eric Gamma should always be a deja vu."



I once was programming something and when I was finished thought "shouldn't this be a perfect fit for Memento?". When I looked it up (hadn't used it before), I found that I already was using it.
bparanj
Greenhorn

Joined: May 27, 2002
Posts: 27
Before you begin coding a particular design pattern for your problem, read the intent section of the Design Pattern to decide if it is applicable to your context.

Over-engineering will lead to the same problems as procedural code with no patterns at all. How do you know that you are not using too many patterns that are not required? The answer lies in the elegance of the resulting solution. Does it resolve the forces and fit your constraints well? It is elegant in the sense it helps us to conquer complexity instead of introducing unnecessary complexity.


Moderator : <a href="http://groups.yahoo.com/group/OOAD_UML/" target="_blank" rel="nofollow">http://groups.yahoo.com/group/OOAD_UML/</a> <br />Home : <a href="http://www.zepho.com" target="_blank" rel="nofollow">http://www.zepho.com</a>
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

"bparanj"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design Patterns
 
Similar Threads
New to design patterns
How are questions about Design Patterns?
To what extent should we use Factory pattern
Do I *have* to use a design pattern?
Design Patterns