[go: up one dir, main page]

0% found this document useful (0 votes)
12 views19 pages

OOP Unit 6 Session5

Uploaded by

adityakauthkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views19 pages

OOP Unit 6 Session5

Uploaded by

adityakauthkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Marathwada Mitra Mandal's

COLLEGE OF ENGINEERING, PUNE


Accredited with ‘A’ Grade by NAAC, Recipient of “Best College Award 2019” by SPPU
Accredited with NBA(Mechanical Engineering & Electrical Engineering)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---

Department of Information Technology

Unit VI: : File Handling and Design Patterns


Session: 5
Subject: Object Oriented Programming

Class : SE IT (2019 Course)


Course Objectives:

1. Apply concepts of object-oriented paradigm.

2. Design and implement models for real life problems by using


object- oriented programming.

3. Develop object-oriented programming skills.


Course Outcome
Statement
Course Outcome At the end of the course, a student will be able to (write/install/solve/apply/design) Blooms Level

214444.1 Differentiate various programming paradigms. L4

214444.2 Identify classes, objects, methods, and handle object creation, initialization, and Destruction to L2
model real-world problems.

214444.3 Identify relationship among objects using inheritance and polymorphism principles L2

214444.4 Design an application to handle different types of exceptions L6

214444.5 Develop a real world application using files for persistent data storage L6

214444.6 Apply appropriate design patterns to provide object-oriented solutions L3


Design Patterns

• Design patterns represent the best practices used


by experienced object-oriented software developers.
• Design patterns are solutions to general
problems that software developers faced during software
development.
• These solutions were obtained by trial and error by
numerous software developers over quite a substantial period of
time.
•A design patterns are well-proved solution for
solving the specific problem/task.
Design Patterns

• But remember one-thing, design patterns are programming language


independent strategies for solving the common object-oriented design
problems. That means, a design pattern represents an idea, not a particular
implementation.

• By using the design patterns you can make your code more flexible,
reusable and maintainable. It is the most important part because java
internally follows design patterns.

• To become a professional software developer, you must know at least


some popular solutions (i.e. design patterns) to the coding problems.
Design Pattern - Advantages

1. They are reusable in multiple projects.


2. They provide the solutions that help to define the system architecture.
3. They capture the software engineering experiences.
4. They provide transparency to the design of an application.
5. They are well-proved and testified solutions since they have been built
upon the knowledge and experience of expert software developers.
6. Design patterns don’t guarantee an absolute solution to a problem. They
provide clarity to the system architecture and the possibility of building a
better system.
When should we use the design patterns?
• We must use the design patterns during the
analysis and requirement phase of SDLC(Software
Development Life Cycle).

• Design patterns ease the analysis and requirement


phase of SDLC by providing information based on prior
hands-on experiences.
• Design Patterns developed by -Erich Gamma, Richard Helm, Ralph
Johnson, and John Vlissides (GoF)
• Categorization of design patterns:
• Basically, design patterns are categorized into two parts:

1. Core Java (or JSE) Design Patterns.


2. JEE Design Patterns.
Java Design Patterns - Categories

1.Creational Design Pattern


• Factory Pattern
• Abstract Factory Pattern
• Singleton Pattern
• Prototype Pattern
• Builder Pattern.
Java Design Patterns-
Categories
2. Structural Design Pattern
• Adapter Pattern
• Bridge Pattern
• Composite Pattern
• Decorator Pattern
• Facade Pattern
• Flyweight Pattern
• Proxy Pattern
Java Design Patterns- Categories

3. Behavioral Design Pattern


• Chain Of Responsibility Pattern
• Command Pattern
• Interpreter Pattern
• Iterator Pattern
• Mediator Pattern
• Memento Pattern
• Observer Pattern
• State Pattern
• Strategy Pattern
• Template Pattern
• Visitor Pattern
Java Design Patterns
Java Design Patterns - Example

• Problem Given:
• Suppose you want to create a class for which only a single instance
(or object) should be created and that single object can be used by all
other classes.

• Solution:
• Singleton design pattern is the best solution of above specific
problem. So, every design pattern has some specification or set of
rules for solving the problems.
Creational Design Pattern - Singleton

• Singleton Pattern says that just "define a class that has only one instance
and provides a global point of access to it".

• In other words,a class must ensure that only single


instance should be created and single object can be used by all
other classes.

• There are two forms of singleton design pattern

⮚ Early Instantiation: creation of instance at load time.


⮚ Lazy Instantiation: creation of instance when required.
Creational Design Pattern - Singleton

• Advantage of Singleton design pattern


• Saves memory because object is not created at each request. Only
single instance is reused again and again.

• Usage of Singleton design pattern


• Singleton pattern is mostly used in multi-threaded and database
applications. It is used in logging, caching, thread pools, configuration
settings etc.
Singleton – Class Diagram
SingleObject.java SingletonPatternDemo.java

public class SingleObject {


//create an object of SingleObject
private static SingleObject instance = new SingleObject(); public class SingletonPatternDemo
//make the constructor private so that this class cannot be { public static void main(String[]
//instantiated args) {

private SingleObject(){} //illegal construct


//Get the only object available //Compile Time Error: The constructor SingleObject() is not visible
public static SingleObject getInstance(){ //SingleObject object = new SingleObject();
return instance;
//Get the only object available
} SingleObject object = SingleObject.getInstance();
public void showMessage()
//show the message
{ System.out.println("Hello object.showMessage();
World!"); }
} }

}
Student’s evaluation

1 Categories Java Design patterns?


2. Explain the advantages of Java design pattern?
Assignment for next session

Explain the Singleton pattern?


Wrap up

A brief refresher summary of Introduction, Types of Design Patterns,


Singleton

You might also like