0

I want to understand how to implement design patterns such as factory pattern, template pattern, Strategy pattern, visitor pattern, decorator pattern, and so on in a Spring application.

I need a case study which covers these patterns in Spring core or spring web.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
Piyu
  • 11
  • 1
  • Not Spring, but if you want to see design pattern examples in Java, read this excellent answer: http://stackoverflow.com/a/2707195/342852 – Sean Patrick Floyd Apr 05 '17 at 15:51
  • This question is way too broad. Please ask a precise question if you have one. – Guillaume F. Apr 05 '17 at 16:13
  • This question is not broad. Spring framework is using these design patterns. Example: ApplicationContext is using factory pattern to instantiate required objects and template pattern is used for JDBCTemplate, HibernateTemplate, and so on. – Piyu Apr 05 '17 at 16:27
  • Thanks patrick for sharing the link. It is indeed very helpful to understand about design patterns. – Piyu Apr 05 '17 at 16:45

1 Answers1

4

If you are using Spring, you do not need to implement Factory or other Creational patterns while Spring creates objects for you via BeanFactory, so Singleton, Prototype, Factories, Builder are already in.
Also if you need Observer, you can use ApplicationListener from Spring.

For other patterns you can use classical Java implementation. Reference implementation can be found here or here.

In addition, Spring internally is using patterns like Proxy, Adapter, Decorator, Template method, ...

dstar55
  • 938
  • 6
  • 11
  • Also, I would like to share my view point on using design patterns in Spring applications. My main issue was how to decide which design pattern to use for if..else/switch-case constructs, else the code just keeps on expanding with them making a tight-coupling. I – Piyu Apr 08 '17 at 13:15
  • I refereed this link on how a developer can eliminate switch statements: http://blogs.microsoft.co.il/gilf/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements/ – Piyu Apr 08 '17 at 13:23