• 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

Using Design Patterns in Real Life?

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i do so small functionalities in my application, that i never felt to use the design pattern, as i think which can be accomplished in few lines of code around-100, what is the need of making new classes ?

Generally, you think of applying design pattern when more than 1 functionality should be implemented.
In real scenario's most of the time, i found very less places where any of 23 GOF patterns can be applied.

Anyway it depends person to person working on kind of work.

Can you share your expertise, the time you often use apply Design pattern ?
 
Sheriff
Posts: 22791
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most used design pattern in Java is most definitely the Iterator pattern - you use it every time you iterate over a Collection or Set, and some people use it for Lists as well. And every time you use the for-each loop on an Iterable, BAM, there is the Iterator pattern again

The Java API uses several others as well:
  • MVC in Swing (JComboBox, JList, JTable, etc)
  • Singleton (Runtime, Toolkit, etc)
  • Factory Method (URL.openConnection() comes to mind, there are several others as well)
  • Abstract Factory (java.net.ContentHandlerFactory, java.rmi.server.RMIServerSocketFactory, java.rmi.RMIClientSocketFactory, etc)
  • Decorator (Collections.unmodifiableXXX, Collections.synchronizedXXX, etc)
  • Flyweight (String objects often share their char[] data)
  • Proxy (java.lang.reflect.Proxy even has the same name)
  • Template Method (just about every protected abstract method)
  • ...
  •  
    Amandeep Singh
    Ranch Hand
    Posts: 856
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Definitely they are being used in Java API's. But i was wondering about the implementation of design patterns in day to day coding.
     
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I feel that, to some extend, you are right. When coding a single feature, it might not be useful to use design patterns.

    However, when doing any kind of design or architecture of the system, then the design patterns are very very practical. Also, if your single feature grows to something bigger, then you will need to refactor things in some way to simplify your code, at that point you will probably need the design patterns.
     
    Ranch Hand
    Posts: 36
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Disclaimer for Amandeep: The following post doesn't specifically answer your question. My apologies.

    Well, as Rob said, the Java API uses many design patterns. If I may suggest a line of thought: to use design patterns effectively, you need knowledge, skill, and experience, and the Java API was written by programmers of that ilk.

    Since design patterns are supposed to be common tools and/or ideas, suggesting that design patterns aren't useful would make me suspect that the programmer either (1) doesn't understand design patterns, or (2) isn't experienced enough to use them. He might as well say "jigsaws are useless."

    I'll try to put it another way: if a programmer is truly comfortable with a design pattern, it's not an issue of trying to figure out its uses; it's a matter of picking up a hammer because you have a nail in front of you.

    Keep in mind I'm not claiming that if you don't use design patterns, you're not a skilled programmer. Indeed, if you are skilled, you're very likely using design patterns without knowing it. After all, the GoF didn't create design patterns, they just wrote them down:

    Design Patterns, page 2 wrote:None of the design patterns in this book describes new or unproven designs. We have included only designs that have been applied more than once in different systems. Most of these designs have never been documented before. They are either part of the folklore of the object-oriented community or are elements of some successful object-oriented systems—neither of which is easy for novice designers to learn from. So although these designs aren't new, we capture them in a new and accessible way: as a catalog of design patterns having a consistent format.



    p.s. Every pattern in the book ends with a "Known Uses" section.
     
    Ranch Hand
    Posts: 86
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Totally agree with David. I dare to add something more.
    I use to classify the OOP programmers in three main categories:
    - programmers inside methods, very good at turning and twisting bits inside a method, but being usually poor on other things
    - programmers inside classes, average programmers, usually not mastering some specific domain
    - programmers outside classes, designers; they are usually skilled and experienced programmers, who think on today, tomorrow and the year after when do a job.
    IMHO, design patters are the practice of the last kind of programmers and are normal, natural things, not at all exotic and special constructs.
     
    Rancher
    Posts: 600
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Amandeep:

    In my current job, I use several Design Patterns in the automation framework that I have created. I chose the ones I used because it made sense to do it that way, and also because I didn't want to reinvent the wheel. To be more specific, I have several factory classes that use the Singleton pattern, and I use the Flyweight pattern extensively.

    John.
     
    Honk if you love justice! And honk twice for tiny ads!
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic