SlideShare a Scribd company logo
Java EE revisits
Design Patterns
Reza Rahman @reza_rahman
Murat Yener @yenerm
Who we are?
Reza Rahman, Java Evangelist
@reza_rahman
reza.rahman@oracle.com
Murat Yener, Mobile Dev, Java EE enthusiast
@yenerm
murat@muratyener.com
40%
discount with promo
code
VBK43
when ordering
through
wiley.com
valid until end of
December 2015
the beginning
Dijkstra: Object-oriented programming is an
exceptionally bad idea which could only have
originated in California
Design patterns are "descriptions of communicating
objects and classes that are customized to solve a
general design problem in a particular context."
Gang of Four
Enterprise Java and
Design Patterns
• JavaOne 2000 talk (TS-1341) Prototyping patterns
for the J2EE Platform
• Core J2EE Design Patterns (Deepak Alur, John
Crupi and Dan Malks)
• Out-of-box DP implementations with Java EE 5
Singleton
• “Ensure a class has only one instance, and provide
a global point of access to it
• Classic implementation: private constructor, double
locking, static initializer, enums…
• must be thread safe!!
Singleton in Java EE
public class SingletonBean {
}
Singleton in Java EE
@Singleton
public class SingletonBean {
}
Singleton in Java EE
@Singleton
public class SingletonBean {
@PostConstruct
void startUpTask() {
// Perform start up tasks
}
}
Singleton in Java EE
@Startup
@Singleton
public class SingletonBean {
@PostConstruct
void startUpTask() {
// Perform start up tasks
}
}
Singleton (cont.)
• Simple
• No XML configuration needed
• Simple inject to use beans
@Inject SingletonBean bean;
pros & cons
• The Good: expensive objects, caching, global
access…
• The Bad: overuse can cause problems, lazy loading
can cause delays, not lazy loading may cause
memory problems
• and the ugly: considered as an anti-pattern
Abstract Factory
• Creational pattern, to encapsulate creation
• Only the part responsible for creation changes
Abstract Factory in Java EE
public class HelloProducer {
public String getMessage(){
return "Hello World";
}
}
private String message;
Abstract Factory in Java EE
public class HelloProducer {
@Produces
public String getMessage(){
return "Hello World";
}
}
@Inject
private String message;
Abstract Factory in Java EE
public class HelloProducer {
@Produces
public String getMessage(){
return "Hello World";
}
@Produces
public String getGreeting(){
return "Greetings Earthlings";
}
}
@Inject
private String message; ?!?
Abstract Factory in Java EE
public class HelloProducer {
@Produces @Named(“Message")
public String getMessage(){
return "Hello World";
}
@Produces @Named(“Greeting")
public String getGreeting(){
return "Greetings Earthlings";
}
}
@Inject @Named(“Message")
private String message;
pros & cons
• The Good: easy to implement, no boilerplate, works
magically
• The Bad: named annotation is not type safe so
same type of objects better be wrapped or
annotated with qualifiers
• and the ugly: may introduce hard to understand
flow
Facade in Java EE
• Hides the complex logic and provides an interface
for the clients
• Typically used in APIs
• Classic implementation: Just create a method to
hide complexity
Facade in Java EE
public class HelloFacade {
public String executeBusinessLogic(){
//very very complex logic
}
}
private HelloFacade service;
Facade in Java EE
@Stateless
public class HelloFacade {
public String executeBusinessLogic(){
//very very complex logic
}
}
@Inject
private HelloFacade service;
pros & cons
• The Good: stateless or stateful, easy to implement.
Can be exposed as rest or web service endpoint.
• The Bad: overuse may introduce unnecessary
layers
• and the ugly: the name of the pattern :)
Decorator in Java EE
• Adds behavior to objects in runtime.
• More flexible and extensible than inheritance
• Classic implementation: Both the decorator and
target object shares the same interface. Decorator
holds wraps the target object and adds its own
behavior.
Decorator in Java EE
public class ConfigDecorator implements Accessory
{

@Inject 

private Accessory product;



public Long getPrice() {

return getPrice()+1000;

}


}
Decorator in Java EE
@Decorator
public class ConfigDecorator implements Accessory
{

@Inject
@Delegate

private Accessory product;



public Long getPrice() {

return getPrice()+1000;

}


}
Decorator in Java EE
<decorators>
<class>com.patterns.ConfigDecorator</class>
</decorators>
Decorator in Java EE
<decorators>
<class>com.patterns.ConfigDecorator</class>
<class>com.patterns.AnotherDecorator</class>
</decorators>
pros & cons
• The Good: unlike inheritance very easy to change
behavior without breaking legacy code.
• The Bad: needs xml configuration (<CDI 1.1)
• and the ugly: overuse will introduce an execution
flow which is hard to follow
Observer in Java EE
• Don’t call us, we call you!
• Publisher-Subscriber
• Classic implementation: Out-of-box implementation!
Observable Interface, Listeners via inner classes
Observer in Java EE
@Stateless
public class HelloWorldObserver {
public void traceHelloWorlds(
@Observable String message){
//…
}
}
@Stateless
public class PublishService {
@Inject Event<String> event;
public void producer(){
event.fire(“Hey!!” + message);
}
}
Observer in Java EE
@Stateless
public class HelloWorldObserver {
public void traceHelloWorlds(
@Observable SomeObj message){
//…
}
}
@Stateless
public class PublishService {
@Inject Event<SomeObj> event;
public void producer(){
event.fire(new SomeObj());
}
}
pros & cons
• The Good: very very easy, no boiler plate..
• The Bad: may introduce difficulty to follow execution
flow & debug
• and the ugly: nothing.. it’s beautiful :)
MVC in Java EE
• It is not a pattern but a composite collection of other
patterns
• Is used and accepted as industry standard in
almost all UI frameworks.
• Keeps data, logic and UI code separate and easy
to change
• JSF is a clean and simple implementation of MVC
The Model
• Represents data and related business logic
• Model is usually a CDI bean
The View
• Visual representation of Data
• User interacts with View to access data and trigger
business logic
The Controller
• Links view with model
• Directs application flow
MVC in Java EE
• Model: Backing beans which are annotated POJOs
with @Named and @RequestScope
• View: Facelets which are written in XHTML with CSS
• Controller: FacesServlet
Entity
• Lightweight domain object which is persistable
• Annotated with javax.persistance.Entity
• Can represent relational data object/relational
mapping annotations
Entity
@Entity
public class Contact {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
protected String firstName;
protected String lastName;
}
DAO
• Used for accessing the persistent data storage
• Usually singleton
• Simples cases entity manager is the DAO
• Complex cases you create DAOs for entity objects
• Usually a CDI managed bean
DAO
@PersistenceContext
EntityManager em;
//…
SomeObject obj = em.find(SomeObject.class, id);
em.persist(obj);
em.merge(obj);
DTO
• Serializable object to transfer data between layers
• simple cases entity is DTO
• often annotated via JAXB and JSON processing
Java API.
DTO
@Entity
public class Contact {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
protected String firstName;
protected String lastName;
}
DTO
@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Contact {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@XmlTransient
private Long id;
protected String firstName;
protected String lastName;
}
Domain Driven Design
</slides>
Reza Rahman
@reza_rahman
reza.rahman@oracle.com
Murat Yener
@yenerm
murat@muratyener.com
Ad

Recommended

What's New in WebLogic 12.1.3 and Beyond
What's New in WebLogic 12.1.3 and Beyond
Oracle
 
Have You Seen Java EE Lately?
Have You Seen Java EE Lately?
Reza Rahman
 
Move from J2EE to Java EE
Move from J2EE to Java EE
Hirofumi Iwasaki
 
Java EE 7 - Overview and Status
Java EE 7 - Overview and Status
Java Usergroup Berlin-Brandenburg
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7
Hirofumi Iwasaki
 
Java EE 8: On the Horizon
Java EE 8: On the Horizon
Josh Juneau
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6
Bert Ertman
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
Murat Yener
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
Reza Rahman
 
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
Edward Burns
 
Java EE 8 Recipes
Java EE 8 Recipes
Josh Juneau
 
Testing Java EE Applications Using Arquillian
Testing Java EE Applications Using Arquillian
Reza Rahman
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!
Reza Rahman
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot
David Delabassee
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great Match
Reza Rahman
 
EJB and CDI - Alignment and Strategy
EJB and CDI - Alignment and Strategy
David Delabassee
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
Hamed Hatami
 
Java EE Introduction
Java EE Introduction
ejlp12
 
Finally, EE Security API JSR 375
Finally, EE Security API JSR 375
Alex Kosowski
 
Best Way to Write SQL in Java
Best Way to Write SQL in Java
Gerger
 
Java EE7 in action
Java EE7 in action
Ankara JUG
 
Modern web application development with java ee 7
Modern web application development with java ee 7
Shekhar Gulati
 
MVC 1.0 / JSR 371
MVC 1.0 / JSR 371
David Delabassee
 
Down-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EE
Reza Rahman
 
Java EE vs Spring Framework
Java EE vs Spring Framework
Rohit Kelapure
 
Java EE 8 - February 2017 update
Java EE 8 - February 2017 update
David Delabassee
 
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Josh Juneau
 
Java EE 8: What Servlet 4 and HTTP2 Mean
Java EE 8: What Servlet 4 and HTTP2 Mean
Alex Theedom
 
Java EE Revisits Design Patterns
Java EE Revisits Design Patterns
Alex Theedom
 

More Related Content

What's hot (16)

Java EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
Reza Rahman
 
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
Edward Burns
 
Java EE 8 Recipes
Java EE 8 Recipes
Josh Juneau
 
Testing Java EE Applications Using Arquillian
Testing Java EE Applications Using Arquillian
Reza Rahman
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!
Reza Rahman
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot
David Delabassee
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great Match
Reza Rahman
 
EJB and CDI - Alignment and Strategy
EJB and CDI - Alignment and Strategy
David Delabassee
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
Hamed Hatami
 
Java EE Introduction
Java EE Introduction
ejlp12
 
Finally, EE Security API JSR 375
Finally, EE Security API JSR 375
Alex Kosowski
 
Best Way to Write SQL in Java
Best Way to Write SQL in Java
Gerger
 
Java EE7 in action
Java EE7 in action
Ankara JUG
 
Modern web application development with java ee 7
Modern web application development with java ee 7
Shekhar Gulati
 
MVC 1.0 / JSR 371
MVC 1.0 / JSR 371
David Delabassee
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
Reza Rahman
 
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
Edward Burns
 
Java EE 8 Recipes
Java EE 8 Recipes
Josh Juneau
 
Testing Java EE Applications Using Arquillian
Testing Java EE Applications Using Arquillian
Reza Rahman
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!
Reza Rahman
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot
David Delabassee
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great Match
Reza Rahman
 
EJB and CDI - Alignment and Strategy
EJB and CDI - Alignment and Strategy
David Delabassee
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
Hamed Hatami
 
Java EE Introduction
Java EE Introduction
ejlp12
 
Finally, EE Security API JSR 375
Finally, EE Security API JSR 375
Alex Kosowski
 
Best Way to Write SQL in Java
Best Way to Write SQL in Java
Gerger
 
Java EE7 in action
Java EE7 in action
Ankara JUG
 
Modern web application development with java ee 7
Modern web application development with java ee 7
Shekhar Gulati
 

Viewers also liked (17)

Down-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EE
Reza Rahman
 
Java EE vs Spring Framework
Java EE vs Spring Framework
Rohit Kelapure
 
Java EE 8 - February 2017 update
Java EE 8 - February 2017 update
David Delabassee
 
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Josh Juneau
 
Java EE 8: What Servlet 4 and HTTP2 Mean
Java EE 8: What Servlet 4 and HTTP2 Mean
Alex Theedom
 
Java EE Revisits Design Patterns
Java EE Revisits Design Patterns
Alex Theedom
 
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
Java EE 6 & GlassFish 3
Java EE 6 & GlassFish 3
Arun Gupta
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
Anti patterns
Anti patterns
Alex Tumanoff
 
Gwt cdi jud_con_berlin
Gwt cdi jud_con_berlin
hbraun
 
Getting Started With SlideShare
Getting Started With SlideShare
SlideShare
 
jDays Sweden 2016
jDays Sweden 2016
Alex Theedom
 
HTTP/2 and Java: Current Status
HTTP/2 and Java: Current Status
Simone Bordet
 
Java Swing vs. Android App
Java Swing vs. Android App
Johnny Hujol
 
Down-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EE
Reza Rahman
 
Java EE vs Spring Framework
Java EE vs Spring Framework
Rohit Kelapure
 
Java EE 8 - February 2017 update
Java EE 8 - February 2017 update
David Delabassee
 
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVC
Josh Juneau
 
Java EE 8: What Servlet 4 and HTTP2 Mean
Java EE 8: What Servlet 4 and HTTP2 Mean
Alex Theedom
 
Java EE Revisits Design Patterns
Java EE Revisits Design Patterns
Alex Theedom
 
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
Java EE 6 & GlassFish 3
Java EE 6 & GlassFish 3
Arun Gupta
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
Gwt cdi jud_con_berlin
Gwt cdi jud_con_berlin
hbraun
 
Getting Started With SlideShare
Getting Started With SlideShare
SlideShare
 
HTTP/2 and Java: Current Status
HTTP/2 and Java: Current Status
Simone Bordet
 
Java Swing vs. Android App
Java Swing vs. Android App
Johnny Hujol
 
Ad

Similar to Java EE Revisits GoF Design Patterns (20)

SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
Alex Theedom
 
Java EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 
Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015
Alex Theedom
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
Inhacking
 
Alex Theedom Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
Аліна Шепшелей
 
Java EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 
Introduction to design_patterns
Introduction to design_patterns
amitarcade
 
Design Patterns
Design Patterns
Kaushal Shah
 
L09 Frameworks
L09 Frameworks
Ólafur Andri Ragnarsson
 
Devoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementation
Alex Theedom
 
Design Patterns & JDK Examples
Design Patterns & JDK Examples
Ender Aydin Orak
 
Design pattern
Design pattern
Mallikarjuna G D
 
Design pattern is_everywhere_by_saurabh_sharma
Design pattern is_everywhere_by_saurabh_sharma
Saurabh Sharma
 
Software Design Patterns
Software Design Patterns
Pankhuree Srivastava
 
Software Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Software Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
Rahul Malhotra
 
Design Patterns
Design Patterns
Rafael Coutinho
 
Design Patterns - GOF
Design Patterns - GOF
Fanus van Straten
 
GOF Design pattern with java
GOF Design pattern with java
Rajiv Gupta
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
Alex Theedom
 
Java EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 
Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015
Alex Theedom
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
Inhacking
 
Java EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 
Introduction to design_patterns
Introduction to design_patterns
amitarcade
 
Devoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementation
Alex Theedom
 
Design Patterns & JDK Examples
Design Patterns & JDK Examples
Ender Aydin Orak
 
Design pattern is_everywhere_by_saurabh_sharma
Design pattern is_everywhere_by_saurabh_sharma
Saurabh Sharma
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
Rahul Malhotra
 
GOF Design pattern with java
GOF Design pattern with java
Rajiv Gupta
 
Ad

More from Murat Yener (7)

Design patterns with Kotlin
Design patterns with Kotlin
Murat Yener
 
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Murat Yener
 
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
Murat Yener
 
Android WebView, The Fifth Element
Android WebView, The Fifth Element
Murat Yener
 
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
Murat Yener
 
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Murat Yener
 
Eclipsist2009 Rich Client Roundup
Eclipsist2009 Rich Client Roundup
Murat Yener
 
Design patterns with Kotlin
Design patterns with Kotlin
Murat Yener
 
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Murat Yener
 
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
The Horoscope of OSGi: Meet Eclipse Libra, Virgo and Gemini (JavaOne 2013)
Murat Yener
 
Android WebView, The Fifth Element
Android WebView, The Fifth Element
Murat Yener
 
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
Murat Yener
 
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Mobile Java with GWT, Still Write Once Run Everywhere (mGWT+Phonegap)
Murat Yener
 
Eclipsist2009 Rich Client Roundup
Eclipsist2009 Rich Client Roundup
Murat Yener
 

Recently uploaded (20)

On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Rierino Commerce Platform - CMS Solution
Rierino Commerce Platform - CMS Solution
Rierino
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Artificial Intelligence Workloads and Data Center Management
Artificial Intelligence Workloads and Data Center Management
SandeepKS52
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Rierino Commerce Platform - CMS Solution
Rierino Commerce Platform - CMS Solution
Rierino
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Artificial Intelligence Workloads and Data Center Management
Artificial Intelligence Workloads and Data Center Management
SandeepKS52
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 

Java EE Revisits GoF Design Patterns

  • 1. Java EE revisits Design Patterns Reza Rahman @reza_rahman Murat Yener @yenerm
  • 2. Who we are? Reza Rahman, Java Evangelist @reza_rahman [email protected] Murat Yener, Mobile Dev, Java EE enthusiast @yenerm [email protected]
  • 3. 40% discount with promo code VBK43 when ordering through wiley.com valid until end of December 2015
  • 4. the beginning Dijkstra: Object-oriented programming is an exceptionally bad idea which could only have originated in California Design patterns are "descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context." Gang of Four
  • 5. Enterprise Java and Design Patterns • JavaOne 2000 talk (TS-1341) Prototyping patterns for the J2EE Platform • Core J2EE Design Patterns (Deepak Alur, John Crupi and Dan Malks) • Out-of-box DP implementations with Java EE 5
  • 6. Singleton • “Ensure a class has only one instance, and provide a global point of access to it • Classic implementation: private constructor, double locking, static initializer, enums… • must be thread safe!!
  • 7. Singleton in Java EE public class SingletonBean { }
  • 8. Singleton in Java EE @Singleton public class SingletonBean { }
  • 9. Singleton in Java EE @Singleton public class SingletonBean { @PostConstruct void startUpTask() { // Perform start up tasks } }
  • 10. Singleton in Java EE @Startup @Singleton public class SingletonBean { @PostConstruct void startUpTask() { // Perform start up tasks } }
  • 11. Singleton (cont.) • Simple • No XML configuration needed • Simple inject to use beans @Inject SingletonBean bean;
  • 12. pros & cons • The Good: expensive objects, caching, global access… • The Bad: overuse can cause problems, lazy loading can cause delays, not lazy loading may cause memory problems • and the ugly: considered as an anti-pattern
  • 13. Abstract Factory • Creational pattern, to encapsulate creation • Only the part responsible for creation changes
  • 14. Abstract Factory in Java EE public class HelloProducer { public String getMessage(){ return "Hello World"; } } private String message;
  • 15. Abstract Factory in Java EE public class HelloProducer { @Produces public String getMessage(){ return "Hello World"; } } @Inject private String message;
  • 16. Abstract Factory in Java EE public class HelloProducer { @Produces public String getMessage(){ return "Hello World"; } @Produces public String getGreeting(){ return "Greetings Earthlings"; } } @Inject private String message; ?!?
  • 17. Abstract Factory in Java EE public class HelloProducer { @Produces @Named(“Message") public String getMessage(){ return "Hello World"; } @Produces @Named(“Greeting") public String getGreeting(){ return "Greetings Earthlings"; } } @Inject @Named(“Message") private String message;
  • 18. pros & cons • The Good: easy to implement, no boilerplate, works magically • The Bad: named annotation is not type safe so same type of objects better be wrapped or annotated with qualifiers • and the ugly: may introduce hard to understand flow
  • 19. Facade in Java EE • Hides the complex logic and provides an interface for the clients • Typically used in APIs • Classic implementation: Just create a method to hide complexity
  • 20. Facade in Java EE public class HelloFacade { public String executeBusinessLogic(){ //very very complex logic } } private HelloFacade service;
  • 21. Facade in Java EE @Stateless public class HelloFacade { public String executeBusinessLogic(){ //very very complex logic } } @Inject private HelloFacade service;
  • 22. pros & cons • The Good: stateless or stateful, easy to implement. Can be exposed as rest or web service endpoint. • The Bad: overuse may introduce unnecessary layers • and the ugly: the name of the pattern :)
  • 23. Decorator in Java EE • Adds behavior to objects in runtime. • More flexible and extensible than inheritance • Classic implementation: Both the decorator and target object shares the same interface. Decorator holds wraps the target object and adds its own behavior.
  • 24. Decorator in Java EE public class ConfigDecorator implements Accessory {
 @Inject 
 private Accessory product;
 
 public Long getPrice() {
 return getPrice()+1000;
 } 
 }
  • 25. Decorator in Java EE @Decorator public class ConfigDecorator implements Accessory {
 @Inject @Delegate
 private Accessory product;
 
 public Long getPrice() {
 return getPrice()+1000;
 } 
 }
  • 26. Decorator in Java EE <decorators> <class>com.patterns.ConfigDecorator</class> </decorators>
  • 27. Decorator in Java EE <decorators> <class>com.patterns.ConfigDecorator</class> <class>com.patterns.AnotherDecorator</class> </decorators>
  • 28. pros & cons • The Good: unlike inheritance very easy to change behavior without breaking legacy code. • The Bad: needs xml configuration (<CDI 1.1) • and the ugly: overuse will introduce an execution flow which is hard to follow
  • 29. Observer in Java EE • Don’t call us, we call you! • Publisher-Subscriber • Classic implementation: Out-of-box implementation! Observable Interface, Listeners via inner classes
  • 30. Observer in Java EE @Stateless public class HelloWorldObserver { public void traceHelloWorlds( @Observable String message){ //… } } @Stateless public class PublishService { @Inject Event<String> event; public void producer(){ event.fire(“Hey!!” + message); } }
  • 31. Observer in Java EE @Stateless public class HelloWorldObserver { public void traceHelloWorlds( @Observable SomeObj message){ //… } } @Stateless public class PublishService { @Inject Event<SomeObj> event; public void producer(){ event.fire(new SomeObj()); } }
  • 32. pros & cons • The Good: very very easy, no boiler plate.. • The Bad: may introduce difficulty to follow execution flow & debug • and the ugly: nothing.. it’s beautiful :)
  • 33. MVC in Java EE • It is not a pattern but a composite collection of other patterns • Is used and accepted as industry standard in almost all UI frameworks. • Keeps data, logic and UI code separate and easy to change • JSF is a clean and simple implementation of MVC
  • 34. The Model • Represents data and related business logic • Model is usually a CDI bean
  • 35. The View • Visual representation of Data • User interacts with View to access data and trigger business logic
  • 36. The Controller • Links view with model • Directs application flow
  • 37. MVC in Java EE • Model: Backing beans which are annotated POJOs with @Named and @RequestScope • View: Facelets which are written in XHTML with CSS • Controller: FacesServlet
  • 38. Entity • Lightweight domain object which is persistable • Annotated with javax.persistance.Entity • Can represent relational data object/relational mapping annotations
  • 39. Entity @Entity public class Contact { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; protected String firstName; protected String lastName; }
  • 40. DAO • Used for accessing the persistent data storage • Usually singleton • Simples cases entity manager is the DAO • Complex cases you create DAOs for entity objects • Usually a CDI managed bean
  • 41. DAO @PersistenceContext EntityManager em; //… SomeObject obj = em.find(SomeObject.class, id); em.persist(obj); em.merge(obj);
  • 42. DTO • Serializable object to transfer data between layers • simple cases entity is DTO • often annotated via JAXB and JSON processing Java API.
  • 43. DTO @Entity public class Contact { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; protected String firstName; protected String lastName; }
  • 44. DTO @Entity @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Contact { @Id @GeneratedValue(strategy = GenerationType.AUTO) @XmlTransient private Long id; protected String firstName; protected String lastName; }