Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Design patterns confusion ?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have been developing J2EE web applications from last 3 years. I use Struts 2 for the same. Recently I came across these articles about 'Programming to Interface not Implementation' and 'Design Patterns'. And I am completely amazed by the amount of flexibility, security and scalability you get by using these set of rules. I am also looking forward to designing applications and developing Java based APIs. So for that very reason I am reading 'Head First Design Patterns' these days. Though I am now quite familiar with the purpose of using 'design patterns' and 'programming to Interface not Implementation' but when it comes to implementing the same in my application I am completely confused. Even When I implement these rules they seem unnecessary and just for the sake of 'Design Patterns' implementation. My question is for expert developers -

How can I develop 'Programming to Interface not Implementation' coding style ?
What path should I take to learn 'Design Patterns' ?
Are there any other good books that may help learning 'Design Patterns' or 'Interface based programming' besides Head First Design Patterns' ?

I have been trying from last few weeks but of no use. Please help.

Thanks to All
Abhilash ''
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhilash Chander wrote:How can I develop 'Programming to Interface not Implementation' coding style ?


Program to interfaces, not implementations.

You probably already do this to some extent--like when you use an ArrayList you define the variable as a List, or even Collection, not an ArrayList.

If you practice TDD, or something slightly less militant, you'll find yourself doing this a lot, out of necessity: if I'm testing a method that relies on another class I don't necessarily want to use an actual instance of the other class. Instead I'd want to use a mock object to simulate various ways the method under test could behave. If the method uses a specific implementation I'm forced to test both the method, and the class the method uses--and I might not be able to simulate all the behaviors I need to.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read Head First Design Patterns a few months ago I I think it is an excellent book. It explains not only patterns but also why they are good, based on some recommended basic rules (don't repeat code, hide the implementation ie. program to interfaces, etc). I highly recommend you to re-read that book and pay special attention to the reasons for the patterns.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I heartily agree with Francesc's book recommendation. While I am a relatively new convert to Java I found this book to be a well balanced introduction to design patterns.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You could get a copy of Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides (Gang of Four). That's the originator of Design Patterns.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nandini Bhaduri wrote:That's the originator of Design Patterns.


I'd feel more comfortable saying it's the canonical reference work--patterns existed in various forms before they were written down.

On a side note, I have a copy of _Pattern Hatching_ signed by John Vlissides.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic