Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Design patterns

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am a student working on an application for my final year project. I am at the stage in my programming skills of understanding more than I can do! I have produced use cases and some class diagrams but am struggleing to understand how to find and use patterns in my design. I bought the Shalloway and Trott book and this has helped a bit but working on my own its hard to be sure if I have got something right or not. Are there any mentors out there who can guide novices like me into the world of pattern use?
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is hard to mentor long distance and hypothetical. The best place to start is to know the patterns. If you know them you can very easily spot them. Factory/Observer/Iterator/Command etc are used all over the place.
HTH
Sanjay
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recently completed a course on OO design that included some work on patterns and frameworks but as Sanjay says when the work is hypothetical it is difficult to get a good grasp of the concepts. Could someone provide a concrete example of how one pattern would be used in practice?
any comment is appreciated.
scott
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common pattern I find effective is the Factory pattern. Basically, defer the implementation of a particular object to the actual creator at runtime. For example, say you have an interface representing a car. Your code will utilize this interface, but it may not care of its actual implementation (i.e. If it�s a 4 wheel car or 18 wheeler). In this case, you could use a factory to give you a particular instance of a car so that your code is plug and playable at runtime. Your code could say:


<code>
Car myCar = CarFactory.manufacture(�FourWheelCar�);
</code>


where �FourWheelCar� is a runtime creation of a class representing a 4 wheel car which implements the interface, car. You can see with some minor effort that your code is changeable with out recompilation.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glover
I wud agree with you on factory but I always think of ways away from hard coding. Can we use reflection or any other better way to prevent hard coding of class/interface names?
Thanks
Raj
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are three articles I wrote several years ago that detail my experience in building with design patterns -- these were drawn from actual code that I wrote (and often include in the article).

Design Patterns in Order Management Systems:
http://www.ksccary.com/article4.htm
And two articles on Patterns in a Database admin tool:
http://members.aol.com/kgb1001001/Articles/Command/CommandJava.htm
http://members.aol.com/kgb1001001/Articles/JDBCMetadata/JDBC_Metadata.htm
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
    Bookmark Topic Watch Topic
  • New Topic