Advanced Programming Behnam Hatami Fall 2017.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Plab – Tirgul 12 Design Patterns
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Façade Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Todd Snyder Development Team Lead Infragistics Experience Design Group.
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Advanced Programming Rabie A. Ramadan 7.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Patterns in programming
Generator Design Patterns: Singleton and Prototype
Presented by FACADE PATTERN
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
Design Patterns: MORE Examples
Object-Oriented Design
Unit II-Chapter No. : 5- design Patterns
The Object-Oriented Thought Process Chapter 15
Describe ways to assemble objects to implement a new functionality
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns C++ Java C#.
Pertemuan 08 Design Patterns & Anti-Patterns
Introduction to Design Patterns
Design Patterns C++ Java C#.
Design Patterns Based on slides provided by Abbie Jarrett
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Chapter 8, Design Patterns Bridge
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
object oriented Principles of software design
Presented by Igor Ivković
Chapter 6: Using Design Patterns
08/15/09 Design Patterns James Brucker.
Advanced Programming Behnam Hatami Fall 2017.
DESIGN PATTERNS : Introduction
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Advanced ProgramMING Practices
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Advanced ProgramMING Practices
Object Oriented Analysis and Design
Chapter 8, Design Patterns Introduction
Software Design Lecture : 39.
Presentation transcript:

Advanced Programming Behnam Hatami Fall 2017

Agenda OOP Design Design Patterns

interfaces Defines a protocol an interface promises a certain functionality All the classes implementing the interface provide their own implementations for the promised functionality A class combines the state and the behavior of a real object An interface specifies (only) the behavior of an abstract entity

Famous Java Interfaces Comparable<T> int compareTo(T o) java.io.Serializable No method Sometimes, interfaces have no method The interface itself, is the protocol Collection, Itertable, Iterator

Mechanisms of Code Reuse Generics Inheritance Composition interface

Composition Inheritance: is-a Composition: has-a Circle has a center Other examples?

Composition vs. Inheritance You can make a base class And put the common functionality of many classes in it But always check: Whether the is-a relationship exists between the derived classes and the base class If the is-a relationship does not hold, Use composition instead of inheritance Favor Composition over Inheritance

Example

Problems with this Inheritance is-a DynamicDataSet is-a Sorting? No. What if the two types of data set classes have a genuine base class, DataSet?

Notes Favor composition over inheritance Use composition to get code that is easy to change and loosely coupled Make your classes dependent on interfaces, not on the actual implementation findBest(List<T>) class DynamicDataSet { Sorting sorting; Do not depend on MergeSorting

Terminology Association types: composition and aggregation Composition: the lifetime of the contained object and the container object is the same That is not the case with aggregation Body and heart? composition Library and book? aggregation

Composition over inheritance Classes achieve polymorphic behavior and code reuse By containing other classes that implement the desired functionality instead of through inheritance How? typically by creating various interfaces The interfaces represent the desired behaviors We can simulate multiple-inheritance using this technique

Design Patterns A general reusable solution to a commonly occurring problem within a given context in software design Repeatable solution to solve a generic design problem Professionals has formulated solutions to frequently recurring design problems Reusability in the level of software design design patterns are design solutions They are not ready-made solutions like code in a library Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four), Erich Gamma, et al.

Types of Design Patterns Creational patterns About object instantiation examples: singleton, Factory, Abstract Factory, and prototype Structural patterns how related classes and objects are composed together to form a larger structure. examples: Decorator, proxy, and Façade. Behavioral patterns objects communication and flow control e.g. Observer, Iterator, state

Observer Pattern Whenever any change in observable object takes place, you need to inform some classes (observers) as to the changed information interface java.util.Observer public class java.util.Observable Behavioral pattern You may write your own observable classes Perhaps to obey your class hierarchy

Observer public interface Observer { void update(Observable o, Object arg); } public class Observable { private boolean changed = false; private Vector obs; public synchronized void addObserver(Observer o){...} ...

Singleton To make sure that only one instance is present for a particular class (one instance per JVM) Creational pattern

Only One Instance? It is possible to create two instances of Logger. How? getInstance() method should be synchronized

Factory Design Pattern

Factory and Abstract Factory Pattern Creational Pattern Factory classes are usually singletone Abstract factory pattern: a factory of factories introduces one more indirection to create a specified object A client of the abstract factory design pattern first requests a proper factory from the abstract factory object and then it requests an appropriate object from the factory object

Abstract Factory Pattern

Data Access Object Pattern (DAO)

DAO Abstracts the details of the underlying persistence mechanism Hides the implementation details of the data source from its clients Loose coupling between core business logic and persistence mechanism Generic DAO pattern

Decorator Structural patterns also known as Wrapper Allows behavior to be added to an individual object, (either statically or dynamically) without affecting the behavior of other objects from the same class

Decorator

Prototype Creational pattern the type of objects to create is determined by a prototypical instance which is cloned to produce new objects

Prototype (2)

Façade (or Façade) A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A Structural pattern A facade can: make a software library easier to use, understand and test make the library more readable reduce dependencies of outside code on the inner workings wrap a poorly designed collection of APIs with a single well-designed API

References Refactoring: improving the design of existing code, Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts (1999) Java cup

Any Question