SlideShare a Scribd company logo
JAVA design patterns and Basic OOp concepts
What is Java?
Programming Language
Fast
Secure
Reliable
What is Java?
Programming Language
Fast
Secure
Reliable
Some Facts about JAVA:
Developed by JAMES GOSLING at SUN MICROSYSTEMS
Related to two languages C and C++
HOW ?
JAVA derives its Syntax from C and,
Many concepts based on OOPs were influenced by C++
Initially JAVA was named as “Oak” But was renamed by “JAVA” in 1995
3977 classes
The Way JavaWorks :
Objective :Write an Application and make it run on whether
devices your friends have.
The JAVA BUZZWORDS :
Simple
Secure
Portable
Dynamic
Distributed
Object-oriented
Robust(Consistent)
Multithreaded
Architecture neutral
High Performance
Major OOP Principles :
Abstraction
Encapsulation
Inheritance
Polymorphism
Abstraction:
 Manages Complexity(Generalization)
 Hierarchal Classification
 Makes Java more Understandable
Encapsulation:
Binds Code and data Together
Keeps it safe from outside interference and Misuse
It works through Classes. A
AB
C
CD
C is accessible with in this Block
Inheritance :
Process of acquiring the properties of another object
In absence of inheritance, each object needs to define all characteristics
Polymorphism :
An Ability of an object to acquire more than one form
For example:
public interface Vegetarian{ }
public class Animal{ }
public class Deer extends Animal implements Vegetarian{ }
A Deer IS-A Animal
A Deer IS-A Vegetarian
A Deer IS-A Deer
A Deer IS-A Object
Interface :
 It is an Collection of Abstract Methods
 It can contain any no. of methods
 How do it do this???
HOW ?
Lets Design Some
Patterns
General solution to programmers problems faced while designing software
Increase the Code Maintainability
GOF: Erich Gamma, Richard helm, Ralph Johnsons and John vlissides
Helps in Reusing the codes
Time saving and Cost reduction
Types Of Patterns
Creational Pattern:
Way to create Objects while hiding the Creational Logic
Structural Pattern:
Concerns class and object composition
Behavioral pattern:
Referred to communication between objects
J2EE:
Presentation tier.
Classification Of Patterns
Creational pattern:
1. Factory Pattern
2. Singleton Pattern
3. Abstract Factory Pattern
4. Builder Pattern
5. Prototype Pattern
Structural Patterns:
1. Adapter Pattern
2. Composite Pattern
3. Proxy Pattern
4. Flyweight Pattern
5. Façade Pattern
6. Bridge Pattern
7. Decorator Pattern
Behavioral Pattern:
1. Template Method Pattern
2. Mediator Pattern
3. Chain of Responsibility Pattern
4. Observer Pattern
5. Strategy Pattern
6. Command Pattern
7. State Pattern
8. Visitor Pattern
9. Iterator Pattern
10. Memento Pattern
Factory Pattern
Factory Pattern
Comes Under the creational Pattern
Create object without Exposing the Creational Logic
used to instantiate an object from one among a set of classes based on a logic
Assume that you have a set of classes which extends a common super
class or interface. Now you will create a concrete class with a method which
accepts one or more arguments.This method is our factory method.
Factory Pattern
Super Class
SubClass 3Sub Class 2Sub Class 1
Factory Super ClassLogic
Factory Pattern
Adapter Pattern
Allows you to use two Incompatible Interfaces to work together
Used when the client expects a(target) interface
Adapter Class allows the use of available Interface and the target
 interface
Any class can work together as long as the Adapter solves the issue
that All classes must implements every method defined by the
shared interface
Adapter Pattern
Client
Enemy Attacker
<Interface>
Fire weapon():void
Drive Forward():void
Assign driver():void
Enemy Robot Adapter
Fire weapon():void
Drive Forward():void
Assign driver():void
Enemy Robot
Smash with hands():void
walk Forward():void
React to human():void
Enemy Robot
Enemy Attacker
(Target)
Enemy Robot Adapter
(Adaptor)
Enemy Robot
(Adaptee)
Adapter Pattern
Observer Pattern
In observer design pattern multiple observer objects registers with
a subject for change notification.When the state of subject changes,
it notifies the observers. Objects that listen or watch for change are
called observers and the object that is being watched for is called
subject.
Pattern involved is also called as publish-subscribe pattern. Model
view controller (MVC) architecture’s core uses the observer design
pattern.
Observer Pattern
Subject provides interface for observers to register and unregister
themselves with the subject.
Subject knows who its subscribers are.
Multiple observers can subscribe for notifications.
Subject publishes the notifications.
Subject just sends the notification saying the state has changed. It does
not pass any state information.
Once the notification is received from subject, observers call the subject
and get data that is changed.
Observer Pattern
Consider an excel sheet, data is shown to the user in different
views. Generally data is shown in grid cells and as required
different graphs, charts can be created for same data. Underlying
data is same and when that data (subject) state changes all the
different view are updated.
 When multiple
objects depend on
state of one object
and all these multiple
objects should be in
sync with the state of
this one object then
observer design
pattern is the right
choice to apply.
When?
Observer Pattern
Let us take a blog and
subscriber example for
observer design pattern
sample implementation.
Assume that there is a blog
and users register to that
blog for update.When a new
article is posted in the blog,
it will send update to the
registered users saying a
new article is posted.Then
the user will access the blog
and read the new article
posted. In this example, blog
is the subject and user is the
observer.
Proxy Design Pattern
Proxy means ‘in place of’. In attendance roll call, we give proxy for
our friends in college right? ‘Representing’ or ‘in place of’ or ‘on
behalf of’ are literal meanings of proxy and that directly explains
proxy design pattern.
Proxy Design Pattern
Remote Proxy – Represents an object locally which belongs to a
different address space.Think of an ATM implementation, it will
hold proxy objects for bank information that exists in the remote
server.
Virtual Proxy – In place of a complex or heavy object use a
skeleton representation.
Protection Proxy –working on a MNC? If so, you might be well
aware of the proxy server that provides you internet. Saying more
than provides, the right word is censors internet.
Smart Reference – Just we keep a link/reference to the real object
a kind of pointer.
Proxy Design Pattern
Provide a class which will limit access to another class
You may do this for Security reasons, because an Object is intensive
to Create, or is accessed from a remote location.
Proxy Design Pattern
Client
GetATMState
<interface>
+getATMState(): ATMState
+getCashINMachine():int
ATM Proxy
+getATMState(): ATMState
+getCashINMachine():int
ATM Machine
+getATMState(): ATMState
+getCashINMachine():int
MVC Design Pattern
Completely Separates the Calculation and Interface from each other
Model: Data and Model Used to Work with it
View:The Interface
Controller: Coordinates interactions between the view and Model
My Favorite One!!
Rahul Malhotra
rahulbtibusiness@gmail.com
+91-74041-37709
www.facebook.com/btiworld14

More Related Content

PDF
Design patterns
PPTX
GoF Design patterns I: Introduction + Structural Patterns
PDF
Design patterns difference between interview questions
PDF
Design patterns tutorials
PPTX
Gof design patterns
PDF
Basic design pattern interview questions
PPTX
Let us understand design pattern
PDF
Lecture 5 Software Engineering and Design Design Patterns
Design patterns
GoF Design patterns I: Introduction + Structural Patterns
Design patterns difference between interview questions
Design patterns tutorials
Gof design patterns
Basic design pattern interview questions
Let us understand design pattern
Lecture 5 Software Engineering and Design Design Patterns

What's hot (20)

PDF
Java design patterns
DOCX
Java Design Pattern Interview Questions
PDF
Java Design Patterns Tutorial | Edureka
PPT
Design Patterns
PPTX
PPTX
Design pattern-presentation
PDF
GOF Design pattern with java
PPT
Software Design Patterns
PDF
Design Patterns Presentation - Chetan Gole
PPTX
Design pattern
PDF
Gof design pattern
PPT
Design patterns ppt
PPS
Jump start to OOP, OOAD, and Design Pattern
PDF
Java Course 11: Design Patterns
PPTX
Design patterns
PPTX
Behavioral pattern By:-Priyanka Pradhan
PPT
Design Pattern For C# Part 1
PDF
Design Patterns Illustrated
PDF
Design Patterns & JDK Examples
PPT
Design Patterns
Java design patterns
Java Design Pattern Interview Questions
Java Design Patterns Tutorial | Edureka
Design Patterns
Design pattern-presentation
GOF Design pattern with java
Software Design Patterns
Design Patterns Presentation - Chetan Gole
Design pattern
Gof design pattern
Design patterns ppt
Jump start to OOP, OOAD, and Design Pattern
Java Course 11: Design Patterns
Design patterns
Behavioral pattern By:-Priyanka Pradhan
Design Pattern For C# Part 1
Design Patterns Illustrated
Design Patterns & JDK Examples
Design Patterns
Ad

Viewers also liked (20)

PDF
Java Design Patterns: The State Pattern
DOC
Top 9 design pattern interview questions answers
PPTX
Java8 training - Class 1
PPTX
Java8 training - class 2
PPTX
Java8 training - class 3
PPT
Java buzzwords
PPTX
Concurrency with java
PDF
Building Applications with a Graph Database
DOCX
What is concurrency
PDF
Design patterns through java
PDF
PDF
Jumping-with-java8
PPT
Iterator Pattern Baljeet Sandhu 20060621
PPTX
Eclipse e4 Overview
PPTX
Java Hands-On Workshop
PPTX
Apache camel
PPTX
Concurrency & Parallel Programming
PDF
Java day2016 "Reinventing design patterns with java 8"
PDF
Getting Started with IntelliJ IDEA as an Eclipse User
PPTX
Why Transcriptome? Why RNA-Seq? ENCODE answers….
Java Design Patterns: The State Pattern
Top 9 design pattern interview questions answers
Java8 training - Class 1
Java8 training - class 2
Java8 training - class 3
Java buzzwords
Concurrency with java
Building Applications with a Graph Database
What is concurrency
Design patterns through java
Jumping-with-java8
Iterator Pattern Baljeet Sandhu 20060621
Eclipse e4 Overview
Java Hands-On Workshop
Apache camel
Concurrency & Parallel Programming
Java day2016 "Reinventing design patterns with java 8"
Getting Started with IntelliJ IDEA as an Eclipse User
Why Transcriptome? Why RNA-Seq? ENCODE answers….
Ad

Similar to JAVA design patterns and Basic OOp concepts (20)

PPT
Basic Java Concept - Practical Oriented Methodologies
PDF
MCA NOTES.pdf
DOCX
Patterns (contd)Software Development ProcessDesign patte.docx
KEY
Mac/iOS Design Patterns
PPT
Jump Start To Ooad And Design Patterns
DOCX
Repository Pattern in MVC3 Application with Entity Framework
PPTX
1. Mini seminar intro
PDF
Java chapter 3
PPT
Design Pattern with Actionscript
PDF
Object-Oriented Programming in Java.pdf
PPTX
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
PDF
M.c.a. (sem iv)- java programming
PPT
ActionScript Design Patterns
PDF
02 objective-c session 2
PPT
Lecture01
PPTX
OOP design patterns
PDF
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
PPTX
Spring (1)
PPT
Encapsulation
Basic Java Concept - Practical Oriented Methodologies
MCA NOTES.pdf
Patterns (contd)Software Development ProcessDesign patte.docx
Mac/iOS Design Patterns
Jump Start To Ooad And Design Patterns
Repository Pattern in MVC3 Application with Entity Framework
1. Mini seminar intro
Java chapter 3
Design Pattern with Actionscript
Object-Oriented Programming in Java.pdf
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
M.c.a. (sem iv)- java programming
ActionScript Design Patterns
02 objective-c session 2
Lecture01
OOP design patterns
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Spring (1)
Encapsulation

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Pharma ospi slides which help in ospi learning
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Open Quiz Monsoon Mind Game Prelims.pptx
The Final Stretch: How to Release a Game and Not Die in the Process.
Introduction and Scope of Bichemistry.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O5-L3 Freight Transport Ops (International) V1.pdf
Insiders guide to clinical Medicine.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Onica Farming 24rsclub profitable farm business
NOI Hackathon - Summer Edition - GreenThumber.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Week 4 Term 3 Study Techniques revisited.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Pharma ospi slides which help in ospi learning

JAVA design patterns and Basic OOp concepts

  • 2. What is Java? Programming Language Fast Secure Reliable
  • 3. What is Java? Programming Language Fast Secure Reliable
  • 4. Some Facts about JAVA: Developed by JAMES GOSLING at SUN MICROSYSTEMS Related to two languages C and C++ HOW ? JAVA derives its Syntax from C and, Many concepts based on OOPs were influenced by C++ Initially JAVA was named as “Oak” But was renamed by “JAVA” in 1995 3977 classes
  • 5. The Way JavaWorks : Objective :Write an Application and make it run on whether devices your friends have.
  • 6. The JAVA BUZZWORDS : Simple Secure Portable Dynamic Distributed Object-oriented Robust(Consistent) Multithreaded Architecture neutral High Performance
  • 7. Major OOP Principles : Abstraction Encapsulation Inheritance Polymorphism
  • 8. Abstraction:  Manages Complexity(Generalization)  Hierarchal Classification  Makes Java more Understandable
  • 9. Encapsulation: Binds Code and data Together Keeps it safe from outside interference and Misuse It works through Classes. A AB C CD C is accessible with in this Block
  • 10. Inheritance : Process of acquiring the properties of another object In absence of inheritance, each object needs to define all characteristics
  • 11. Polymorphism : An Ability of an object to acquire more than one form For example: public interface Vegetarian{ } public class Animal{ } public class Deer extends Animal implements Vegetarian{ } A Deer IS-A Animal A Deer IS-A Vegetarian A Deer IS-A Deer A Deer IS-A Object
  • 12. Interface :  It is an Collection of Abstract Methods  It can contain any no. of methods  How do it do this??? HOW ?
  • 13. Lets Design Some Patterns General solution to programmers problems faced while designing software Increase the Code Maintainability GOF: Erich Gamma, Richard helm, Ralph Johnsons and John vlissides Helps in Reusing the codes Time saving and Cost reduction
  • 14. Types Of Patterns Creational Pattern: Way to create Objects while hiding the Creational Logic Structural Pattern: Concerns class and object composition Behavioral pattern: Referred to communication between objects J2EE: Presentation tier.
  • 15. Classification Of Patterns Creational pattern: 1. Factory Pattern 2. Singleton Pattern 3. Abstract Factory Pattern 4. Builder Pattern 5. Prototype Pattern Structural Patterns: 1. Adapter Pattern 2. Composite Pattern 3. Proxy Pattern 4. Flyweight Pattern 5. Façade Pattern 6. Bridge Pattern 7. Decorator Pattern Behavioral Pattern: 1. Template Method Pattern 2. Mediator Pattern 3. Chain of Responsibility Pattern 4. Observer Pattern 5. Strategy Pattern 6. Command Pattern 7. State Pattern 8. Visitor Pattern 9. Iterator Pattern 10. Memento Pattern
  • 17. Factory Pattern Comes Under the creational Pattern Create object without Exposing the Creational Logic used to instantiate an object from one among a set of classes based on a logic Assume that you have a set of classes which extends a common super class or interface. Now you will create a concrete class with a method which accepts one or more arguments.This method is our factory method.
  • 18. Factory Pattern Super Class SubClass 3Sub Class 2Sub Class 1 Factory Super ClassLogic
  • 20. Adapter Pattern Allows you to use two Incompatible Interfaces to work together Used when the client expects a(target) interface Adapter Class allows the use of available Interface and the target  interface Any class can work together as long as the Adapter solves the issue that All classes must implements every method defined by the shared interface
  • 21. Adapter Pattern Client Enemy Attacker <Interface> Fire weapon():void Drive Forward():void Assign driver():void Enemy Robot Adapter Fire weapon():void Drive Forward():void Assign driver():void Enemy Robot Smash with hands():void walk Forward():void React to human():void Enemy Robot Enemy Attacker (Target) Enemy Robot Adapter (Adaptor) Enemy Robot (Adaptee)
  • 23. Observer Pattern In observer design pattern multiple observer objects registers with a subject for change notification.When the state of subject changes, it notifies the observers. Objects that listen or watch for change are called observers and the object that is being watched for is called subject. Pattern involved is also called as publish-subscribe pattern. Model view controller (MVC) architecture’s core uses the observer design pattern.
  • 24. Observer Pattern Subject provides interface for observers to register and unregister themselves with the subject. Subject knows who its subscribers are. Multiple observers can subscribe for notifications. Subject publishes the notifications. Subject just sends the notification saying the state has changed. It does not pass any state information. Once the notification is received from subject, observers call the subject and get data that is changed.
  • 25. Observer Pattern Consider an excel sheet, data is shown to the user in different views. Generally data is shown in grid cells and as required different graphs, charts can be created for same data. Underlying data is same and when that data (subject) state changes all the different view are updated.  When multiple objects depend on state of one object and all these multiple objects should be in sync with the state of this one object then observer design pattern is the right choice to apply. When?
  • 26. Observer Pattern Let us take a blog and subscriber example for observer design pattern sample implementation. Assume that there is a blog and users register to that blog for update.When a new article is posted in the blog, it will send update to the registered users saying a new article is posted.Then the user will access the blog and read the new article posted. In this example, blog is the subject and user is the observer.
  • 27. Proxy Design Pattern Proxy means ‘in place of’. In attendance roll call, we give proxy for our friends in college right? ‘Representing’ or ‘in place of’ or ‘on behalf of’ are literal meanings of proxy and that directly explains proxy design pattern.
  • 28. Proxy Design Pattern Remote Proxy – Represents an object locally which belongs to a different address space.Think of an ATM implementation, it will hold proxy objects for bank information that exists in the remote server. Virtual Proxy – In place of a complex or heavy object use a skeleton representation. Protection Proxy –working on a MNC? If so, you might be well aware of the proxy server that provides you internet. Saying more than provides, the right word is censors internet. Smart Reference – Just we keep a link/reference to the real object a kind of pointer.
  • 29. Proxy Design Pattern Provide a class which will limit access to another class You may do this for Security reasons, because an Object is intensive to Create, or is accessed from a remote location.
  • 30. Proxy Design Pattern Client GetATMState <interface> +getATMState(): ATMState +getCashINMachine():int ATM Proxy +getATMState(): ATMState +getCashINMachine():int ATM Machine +getATMState(): ATMState +getCashINMachine():int
  • 31. MVC Design Pattern Completely Separates the Calculation and Interface from each other Model: Data and Model Used to Work with it View:The Interface Controller: Coordinates interactions between the view and Model My Favorite One!!