MPCS – Advanced java Programming

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

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Patterns CS is not simply about programming
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.
DESIGN PATTERNS Redesigning Applications And
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
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.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
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.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
CSE 403, Spring 2008, Alverson Software Design “There are two ways of constructing a software design: one way is to make it so simple that there are obviously.
Testing Extensible Design Patterns in OO Frameworks through Scenario Templates D.S. Sanders Software Verification & Validation.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
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.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
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.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
Design Patterns Spring 2017.
Design Patterns A brief introduction to what they are, why they are useful, and some examples of those that are commonly used.
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
GoF Patterns (GoF) popo.
Introduction to Design Patterns
Common Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
Design Patterns Introduction
Design Patterns Based on slides provided by Abbie Jarrett
How to be a Good Developer
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Design Patterns Part 2: Factory, Builder, & Memento
DESIGN PATTERNS : Introduction
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Informatics 122 Software Design II
Introduction To Design Patterns
Presentation transcript:

MPCS 51037 – Advanced java Programming Java design patterns MPCS 51037 – Advanced java Programming

What are java design patterns & WHY Use them? Solutions to general problems faced in software development Industry standard approach to solve recurring problems Why? Promotes reusability: more robust and maintainable code Faster development, code easier to understand, debug Provides standard terminology Not the specific solution, but they are descriptions/templates for how to best solve a problem Common platform that can be applied to many different situations Formalized best practices Standard terminology

How they came to be 1994 – Gang of Four: Authors Erich Gamma, Richard Helm, Ralph Johnson, & John Vlissides Book: Design Patterns – Elements of Reusable Object-Oriented Software Design Patterns based on these principles of OO design: Program to an interface, not an implementation Favor object composition over inheritance Gang of 4 – authors, published this book which initiated the concept Interface – client doesn’’t need to be aware of the specific types of objects for example, only need to know about interface/ abstract classes Obj composition – containing instances of other classes that implement desired functionality – instead of inheritance from a parent class – more flexible, polymorphism is better implemented this way The book first talks about the capabilities/pitfalls of OOP, and then the rest of the book talks about 23 different patterns The book has examples in C++ and Smalltalk

3 main types of design patterns Creational Patterns Singleton Factory Abstract Factory Builder Prototype Structural Patterns Adapter Composite Decorator Bridge Façade Flyweight Proxy Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Visitor 4th type: J2EE - presentation

Type: Creational Patterns Way to create objects while hiding logic Does not use the “new” operator Offers more flexibility in deciding which objects need to be created for a given case Solution to instantiate an object in the best possible way for the situation Allows for a more general and flexible approach in being able to create different objects Decouples client from the objects it needs to instantiate

Type: Structural patterns Provide different ways to create a class structure Using inheritance to compose interfaces & define ways to create objects to get new functionality E.g. using inheritance & composition to create a large object from small objects Simpler way to define relationships between classes in the structure

Type: Behavioral patterns Concerned with communication & better interaction between objects Provide loose coupling and flexibility to extend easily Loosely couple the implementation and the client to avoid hard coding / dependencies, so the objects can easily talk to each other

Creational: factory Super class with multiple sub classes – return one of the sub-classes Refer to newly created object using a common interface – no need to expose logic to client One of the most widely used patterns – great way to create an object Allows for more long term flexibility, and again more decoupling

Creational: singleton One of the simplest patterns Creates an object making sure only one object gets created Provides a way to access the only object without needing to instantiate the object of the class – private constructor and public accessor method Often control access to resources such as a database connection – have a license for only 1 connection for your database, Singleton makes sure only 1 connection is made

Singleton example: Command center (proImageshop) public class Cc { private static Cc stateManager; private Stage mMainStage, mSaturationStage; private static ArrayList<Image> backImages; private Cc(){ } /** * Create a static method to get instance. */ public static Cc getInstance(){ if(stateManager == null){ stateManager = new Cc(); backImages = new ArrayList<>(); } return stateManager; } getInstance() is the global access point for the outer world to get the instance of this singleton class, private constructor to restrict instantiation from other classes, private static variable

Creational: builder Make and return one object various ways Separates construction of an object from its representation Allows for the same construction process to create different representations Example: constructing a (typical) meal at a restaurant – always has a drink, side, entrée, dessert – but each individual item can vary (chicken vs fish) Similar to factory but key difference – factory is a more simplified version, user doesn’t need to know the subtype. Builder – different subtypes are created by a builder method – allows for finer granularity & detail. Factory requires the object to be built in a single line while Builder allows for setter methods to build up the parameter list – more complicated objects. Using factory can evolve toward using Builder

Structural: adapter Allows interface of an existing class to be used as another interface Helps two normally incompatible interfaces to work together Converts interface into one expected by user Often used to make classes that exist work with other classes without changing source code

Structural: façade Adds an interface to a system to hide complexities Single class with simplified methods Make the client application easier to understand Can wrap a more complicated subsystem with a simpler interface

Behavioral: command Command, Receiver, Invoker, Client Allows for encapsulation of actions within classes – perform action later – “ready to run” Request is sent to invoker which passes it to the encapsulated object that can handle the command and passes it to the corresponding object that executes the command Command interface classically has an execute() method Command objects knows about receiver and invokes a method of the receiver. Receiver does the work – an invoker object knows how to execute a command. Client passes the command object to the invoker object to execute the command Invoker looks for the appropriate object

Behavioral: iterator Used to traverse a container and access elements A way to access elements without exposing underlying representation Interface to traverse different collections

ReSources http://fuzzduck.com/Design-Patterns/Iterator-Pattern.php https://www.javacodegeeks.com/2015/09/java-design-patterns.html https://sourcemaking.com/design_patterns http://www.tutorialspoint.com/design_pattern/index.htm http://www.javatpoint.com/design-patterns-in-java http://www.oodesign.com/design-principles.html