Introduction to Object Oriented Programming. (Hebrew University, CS / Spring 2012 )

Size: px
Start display at page:

Download "Introduction to Object Oriented Programming. (Hebrew University, CS / Spring 2012 )"

Transcription

1 Introduction to Object Oriented Programming (Hebrew University, CS / Spring 2012 )

2 Overview There are many important Object Oriented Design (OOD) principles Today we'll focus on several basic principles closely related to design-patterns: Modularity The Open-Closed principle The Single-Choice principle Program to an interface and not an implementation Reuse mechanisms: Class Inheritance vs. Object Composition OOP Lecture cs huji

3 Modularity A Modular design results in a software that can be broken down to several individual units, denoted modules Modularity is a desired property of software design Modular programs have several benefits Easy to maintain (debug, update) Allow breaking a complex problem into easier sub-problems Allow to easily divide the project into several team members or groups OOP Lecture cs huji

4 Modularity A design method which is modular should satisfy 5 fundamental requirements: Decomposability Composability Understandability Continuity Protection OOP Lecture cs huji

5 Decomposability Decomposability A software construction method satisfies Modular Decomposability if it: Decomposes a software problem into a small number of less complex sub-problems These sub-problems are connected by a simple structure, and independent enough to allow further work to proceed separately on each of them OOP Lecture cs huji

6 Decomposability A corollary of decomposability is division of labor A decomposed system is easier to distribute among different people or groups A good example: Top-Down Design A typical counter-example: a software system that includes a global initialization module (why?) OOP Lecture cs huji

7 Composability Composability A method satisfies Modular Composability if it produces software elements which may be freely combined with each other to produce new systems Possibly in an environment quite different from the one in which they were initially developed OOP Lecture cs huji

8 Composability Elements should be sufficiently autonomous Composability is directly connected with the goal of reusability Design software elements performing well-defined tasks and usable in widely different contexts Examples: Software libraries (or packages) OOP Lecture cs huji

9 Composability Vs. Decomposability Composability and decomposability are independent. In fact, these criteria are often at odds Top-down design, for example, which we saw as a technique favoring decomposability, tends to produce modules that are not easy to combine with modules coming from other sources OOP Lecture cs huji

10 Understandability Understandability A software design favors Modular Understandability if it produces software in which a human reader can understand each module without having to know anything about the others At worst, by having to examine only a few of the others The importance of this criterion follows from its influence on the maintenance process This is not the same as readability OOP Lecture cs huji

11 Modular Continuity Continuity A method satisfies Modular Continuity if, in the software architectures that it yields, a small change in a problem specification will trigger a change in just one module, or a small number of modules The term continuity is drawn from an analogy with the notion of a continuous function in mathematical analysis OOP Lecture cs huji

12 Modular Protection Modular Protection A method satisfies Modular Protection if the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst only propagate to a few neighboring modules The underlying issue, that of failures and runtime errors, is central to software engineering The criterion does not address the avoidance or correction of errors, but the aspect that is directly relevant to modularity: their propagation i.e. Exception handling OOP Lecture cs huji

13 The Open-Closed principle Software Entities (Classes, Modules, Functions, etc.) should be open for extension but closed for modification (Meyer, 1988) A single change to a program a cascade of changes to dependent modules bad design The program becomes fragile, rigid and un-reusable Violation of the Continuity principle The open-closed principle attacks this by stating that you should design modules that never change Requirements change extend the modules by adding new code, not by changing old code that already works! OOP Lecture cs huji

14 The Open-Closed principle Modules that conform to the open-closed principle have two primary attributes: They are Open for Extension : the behavior of the module can be extended; we can make the module behave in new and different ways as the requirements of the application change They are Closed for Modification : the source code of such a module is inviolate. No one is allowed to change it OOP Lecture cs huji

15 The Open-Closed principle Shape example We have an application that must be able to draw circles and squares on a standard GUI The circles and squares are drawn in a particular order The program traverses and draws a list of circles and squares in a given order Possible solutions: Procedural solution define a class for each type and use it when drawing OOP solution using an abstract class shape OOP Lecture cs huji

16 Shape Example Procedural Solution void drawallshapes(shape[] list) { for (int i=0; i<list.length; i++) { Shape s = list[i]; int type = gettype(s); switch (type){ case SQUARE: drawsquare((square)s); break; case CIRCLE: drawcircle((circle)s); break; } } } OOP Lecture cs huji

17 Procedural Solution What's Wrong Here? The function drawallshapes() does not conform to the open-close principle since it is not closed against new kinds of shapes If we wanted to extend this function to draw a list of shapes that included triangles, we would have to modify it This program is only a simple example The switch statement in drawallshapes() could be repeated over and over again in various functions, each one doing something a little different Adding a new shape means hunting for every such switch statement and adding the new shape OOP Lecture cs huji

18 public class Shape { } The Shape Example OOP Solution public abstract void draw(); public class Square extends Shape { } public void draw(){..} public class Circle extends Shape { } public void draw(){..} void DrawAllShapes(Shape[] list) { } for (Shape currshape : list) currshape.draw(); OOP Lecture cs huji

19 OOP Solution Advantages Extending the behavior of the drawallshapes() function to draw a new kind of shape, is done by adding a new derivative of the Shape class drawallshapes() does not need to change drawallshapes() conforms to the open-closed principle. Its behavior can be extended without modifying it OOP Lecture cs huji

20 The Open-Closed Principle Related Concepts Make all Member Variables Private (Encapsulation) A program s public methods (it s API) rarely changes In contrast, members are considered part of the internal structure Changing them is considered a legitimate change in the software When the members of a class change, every method that depends upon those variables must be changed No function that depends upon a variable can be closed with respect to that variable Instead of forcing one method to change, we are forcing multiple methods Alternatives to using public members are usually inexpensive OOP Lecture cs huji

21 The Open-Closed Principle Related Concepts Run-Time Type Information (RTTI) is Dangerous Another very common proscription is the one against dynamic casts using, for example, the instanceof operator OOP Lecture cs huji

22 The Single-Choice Principle Whenever a software system must support a set of alternatives, one and only one module in the system should know their exhaustive list By doing this, we prepare the scene for later changes: If variants are added, we will only have to update the module which has the information the point of single choice All others, in particular its clients, will be able to continue their business as usual This principle interacts with the open-closed principle: if we must have some exhaustive list of our options, keep it in one place, so that this is the only place the needs to be changed upon updates OOP Lecture cs huji

23 The Shape Example OOP Solution Shape[] loadallshapes(string[] list) { } Shape[] shapes = new Shape[list.length]; for (int i = 0 ; i < list.length ; ++i) { } if (list[i].equals( Square )) { shapes[i] = new Square(); } else if (list[i].equals( Circle )) { } return shapes; shapes[i] = new Circle(); One method must know all the options. It cannot be closed for changes OOP Lecture cs huji

24 The Shape Example OOP Solution void drawallshapes(shape[] list) { } for (Shape currshape : list) currshape.draw(); void deleteallshapes(shape[] list) { for (Shape currshape : list) currshape.delete(); }. All other methods don t need to know the options. They are closed to changes OOP Lecture cs huji

25 Program to an Interface and not an Implementation Using inheritance or interfaces allows us to define a family of classes which share their API Clients remain unaware of the specific type of objects they use Allows to replace implementation details without affecting the clients This greatly reduces implementation dependencies between subsystems OOP Lecture cs huji

26 Reuse Mechanisms Inheritance vs. Composition What is the right way to build reusable software? The two most common techniques for reusing functionality are inheritance and object composition (class) Inheritance Define an implementation of one class in terms of another's Called white-box reuse since the internals of the parent are visible to its subclasses OOP Lecture cs huji

27 Reuse Mechanisms Inheritance public class B { } protected void foo() { } public class A extends B { } Now, A got the foo() method for free and can use it OOP Lecture cs huji

28 Reuse Mechanisms Inheritance vs. Composition Object Composition An alternative to class inheritance New functionality is obtained by assembling (or composing) objects to get more complex functionality Requires that objects being composed have well defined interfaces Called black-box reuse because no internal details of objects are visible. Objects appear only as black boxes OOP Lecture cs huji

29 Reuse Mechanisms Composition public class B { } public void foo() { } public class A { private B b; } public A(B b) { } this.b = b; Now, A can use the foo() code by calling b.foo() OOP Lecture cs huji

30 Inheritance Pros of inheritance: Straightforward to use (supported by the programming language): enables polymorphism Defined statically at compile time Easier to modify the implementation being reused by overriding Cons of inheritance: An implementation cannot be changed at runtime Breaks encapsulation a subclass is exposed to details of the parent's implementation (protected members/methods) Subclass implementation is bound to parent implementation Any change in the parent forces the subclass to change A class can only extend a single parent-class OOP Lecture cs huji

31 Object Composition Pros of object composition: Defined dynamically at runtime Encapsulation is not broken and therefore any object can be replaced at runtime by another as long as it has the same type Substantially fewer implementation dependencies Helps keep each class encapsulated and focused on one task A class may compose as many objects as it wants Cons of object composition: A composition based design has more objects (if fewer classes) No support for polymorphism The system's behavior will depend on their interrelationships instead of being defined in one class OOP Lecture cs huji

32 Reuse Mechanisms Inheritance vs. Composition Use inheritance when: A is inherently a B A dog is an animal Use object composition when: You mainly want to reuse code When it makes more sense to extend A by another class C If you only need polymorphism (but an A is not a B), use object composition + interfaces Inheritance and object composition work together OOP Lecture cs huji

33 So far Among most important OOP design principles Modularity Open-closed Single-choice Program to an interface and not an implementation Class Inheritance vs. Object Composition OOP Lecture cs huji

34 Design Patterns Properties Reminder Describes a proven approach to dealing with a common situation in programming/design Suggests what to do to obtain an elegant, modifiable, extensible, flexible & reusable module Shows, at design time, how to avoid problems that may occur much later Is independent of specific contexts or languages OOP Lecture cs huji

35 Design Patterns Types The different design patterns can be (roughly) divided into 3 different categories Creational patterns These patterns deal with creating objects (instantiation) For example: Factory Structural patterns These patterns deal with the objects structure (composition) For example: Decorator Behavioral patterns These pattern handle the objects behavior (communication between objects) For example: Iterator OOP Lecture cs huji

36 Delegation Delegation is a way of making composition as powerful for reuse as inheritance In delegation, two objects are involved in handling a request: a receiving object delegates operations to its delegate This is analogous to subclasses deferring requests to parent classes (how?) A structural pattern OOP Lecture cs huji

37 Delegation public class B { } public void foo() { } public class A { private B b; public A(B b) { this.b = b; } public void foo() { b.foo(); } A delegates its foo() requests to b A can also perform additional actions in foo() } OOP Lecture cs huji

38 Delegation Question: Should Window be a Rectangle or have a Rectangle? Answer: It should have a rectangle The window class might reuse the behavior of Rectangle, by keeping a Rectangle instance variable and delegating Rectangle-specific behavior to it OOP Lecture cs huji

39 Delegation Main advantage easy to compose behaviors at runtime and to change the way they are composed Example: easy to make the window circular, by replacing the Rectangle instance with a Circle instance Disadvantages: Dynamic, highly parameterized software is harder to understand than static software (like composition in general) Some runtime inefficiencies In summary: a good design choice when it simplifies more than it complicates! OOP Lecture cs huji

40 Decorator Design Pattern Reminder In order to enhance functionality of class A (InputStream): Build class B (BufferedInputStream) that Extends A (shares its API) Composes an object of type A Constructor of B receives an object of type A and remembers it B forwards all requests (= delegates) to the A component and may perform additional actions before or after forwarding Is not a data source by itself, but uses A as a data source The transparency allows the decorators to be nested recursively, thereby allowing an unlimited number combinations! OOP Lecture cs huji

41 To Summarize Let A,B be 2 classes A Composes B if A holds an instance of B (as a member or a local variable) A Delegates B if A composes B and forwards requests to the composed instance (of type B) s methods A Decorates B if A delegates B and extends B OOP Lecture cs huji

42 The Strategy Pattern Intent Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it A behavioral pattern OOP Lecture cs huji

43 Strategy Pattern Applicability Use the Strategy pattern whenever: There exist different variants of an algorithm An algorithm uses data that clients shouldn't know about. Use this pattern to avoid exposing complex, algorithmspecific data structures A class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move related conditional branches into their own Strategy class Relates to the single-choice principal OOP Lecture cs huji

44 Strategy Example A class wants to decide at run-time what algorithm it should use to sort an array. Many different sort algorithms are already available Solution: Encapsulate the different sort algorithms using the Strategy pattern! class SomeCollection { } private Comparable[] _contents; private SortStrategy _sorter; public void sortcontents() { } _sorter.sort(_contents);. interface SortStrategy { void sort(comparable[] a) ; } class Quicksort implements SortStrategy { public void sort(comparable[] a) { } } OOP Lecture cs huji

45 Pros and Cons of Strategy Pros Provides an alternative to subclassing the main class to get a variety of algorithms or behaviors Eliminates large conditional statements Provides a choice of implementations for the same behavior Cons Increases the number of objects Each algorithm must use the same Strategy interface OOP Lecture cs huji

46 Factory Patterns A factory is an object used to create other objects A factory has methods for creating the objects it supports These methods may receive parameters which define the type and properties of the created object Factories are used in situations where deciding which object to create is a complex task The factory may create the object dynamically, return it from some object pool, do complex initialization, etc. Many creational design patterns implement this concept OOP Lecture cs huji

47 The Singleton Pattern Intent Ensure a class only has exactly one instance, and provide a global point of access to it Motivation If we want a single instance of a class to exist in the system We want just one window manager, or just one factory for a family of products We need to have that one instance easily accessible Additional instances of the class cannot be created A creational pattern, which implements the factory concept OOP Lecture cs huji

48 Implementing Singletons Use a static variable to the single instance of the class Make the constructor private Instance creation is done using the static instance() method This method always returns a reference to the same single static object This way only one instance at most is created OOP Lecture cs huji

49 Implementing Singletons class Singleton { private static Singleton single = null; private Singleton () { } public static Singleton instance() { if (single==null) { single = new Singleton(); } } } return single; OOP Lecture cs huji

50 Singleton and Subclassing Using a single private constructor makes it impossible to subclass This isn t such a big problem, as in many cases subclassing singletons is not a good idea In order to allow inheritance, make the constructor protected But then clients who extend the class can create many instances, which breaks the pattern OOP Lecture cs huji

51 So far A few new design patterns Delegation Decorator Strategy The Factory concept Singleton OOP Lecture cs huji

52 Ex3 Input Example a############################ #############_############## ############# ############# #_########### ############ #_########### ########### #_######### ########## # ##### # ####### # ## # ##### # # #### # # # ### # # ### ### # # ## # # ## # # ## # # ### # # ### # # #### # # # ##### # #### ######## # ######## ########## #_############ ############ #_############_############# absolutist:one who advocates absolutism absolver:someone who grants absolution absorbency:the property of being absorbent absorption:the mental state of being preoccupied by something abstemiousness:moderation in eating and drinking abstention:the trait of abstaining (especially from alcohol) abuja:capital of Nigeria in the center of the country abulia:a loss of will power academe:the academic world academia:the academic world academic:an educator who works at a college or university acarina:mites and ticks acarine:mite or tick acariosis:infestation with itch mites acaryote:a cell without a nucleus (as an erythrocyte) acceleration:(physics) a rate of change of velocity acceptation:acceptance as true or valid accessory:a supplementary component acetyl:the organic group of acetic acid (CH3CO-) OOP Lecture cs huji

53 Ex3 Output Example OOP Lecture cs huji

54 Ex3 goals Working with supplied code & inter faces, including generics code [lecture 5] Implementing DFS (depth-first search) [DAST lectures] Working with java collections including Hash & Tree implementations [lecture 6] Using design patterns: you are advised to use the Strategy pattern [lecture 7] OOP Lecture cs huji

Object-Oriented Concepts and Design Principles

Object-Oriented Concepts and Design Principles Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation

More information

Topics in Object-Oriented Design Patterns

Topics in Object-Oriented Design Patterns Software design Topics in Object-Oriented Design Patterns Material mainly from the book Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides; slides originally by Spiros Mancoridis;

More information

CS 520 Theory and Practice of Software Engineering Fall 2018

CS 520 Theory and Practice of Software Engineering Fall 2018 Today CS 520 Theory and Practice of Software Engineering Fall 2018 Object Oriented (OO) Design Principles September 13, 2018 Code review and (re)design of an MVC application (and encapsulation) Polymorphism

More information

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011 Expanding Our Horizons CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011 1 Goals of the Lecture Cover the material in Chapter 8 of our textbook New perspective on objects and encapsulation

More information

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.) Design Pattern CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.) A. Design Pattern Design patterns represent the best practices used by experienced

More information

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1 What is a Design Pattern? Each pattern Describes a problem which occurs over and over again in our environment,and then describes the core of the problem Novelists, playwrights and other writers rarely

More information

CS 320 Introduction to Software Engineering Spring March 06, 2017

CS 320 Introduction to Software Engineering Spring March 06, 2017 CS 320 Introduction to Software Engineering Spring 2017 March 06, 2017 Recap: types of Polymorphism Recap: types of Polymorphism Ad-hoc polymorphism (e.g., operator overloading) a + b String vs. int, double,

More information

Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it

Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it Design Patterns The Gang of Four suggests a few strategies for creating good o-o designs, including Façade Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it One

More information

CS 520 Theory and Practice of Software Engineering Fall 2017

CS 520 Theory and Practice of Software Engineering Fall 2017 CS 520 Theory and Practice of Software Engineering Fall 2017 OO design principles September 14, 2017 Today Code review and (re)design of an MVC application OO design principles Information hiding (and

More information

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Today we are going to talk about an important aspect of design that is reusability of design. How much our old design

More information

CS 320 Introduction to Software Engineering Spring March

CS 320 Introduction to Software Engineering Spring March CS 320 Introduction to Software Engineering Spring 2017 March 20 2017 Today Logistics: timeline and assignments Overview of the study guide (midterm exam) Overview of the SDD requirements Recap of software

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 4: OO Principles - Polymorphism http://courses.cs.cornell.edu/cs2110/2018su Lecture 3 Recap 2 Good design principles.

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

SDC Design patterns GoF

SDC Design patterns GoF SDC Design patterns GoF Design Patterns The design pattern concept can be viewed as an abstraction of imitating useful parts of other software products. The design pattern is a description of communicating

More information

Software Engineering

Software Engineering Software Engineering CSC 331/631 - Spring 2018 Object-Oriented Design Principles Paul Pauca April 10 Design Principles DP1. Identify aspects of the application that vary and separate them from what stays

More information

CS342: Software Design. November 21, 2017

CS342: Software Design. November 21, 2017 CS342: Software Design November 21, 2017 Runnable interface: create threading object Thread is a flow of control within a program Thread vs. process All execution in Java is associated with a Thread object.

More information

COURSE 2 DESIGN PATTERNS

COURSE 2 DESIGN PATTERNS COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecturer: Raman Ramsin Lecture 20: GoF Design Patterns Creational 1 Software Patterns Software Patterns support reuse of software architecture and design. Patterns capture the static

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

What is a Pattern? Lecture 40: Design Patterns. Elements of Design Patterns. What are design patterns?

What is a Pattern? Lecture 40: Design Patterns. Elements of Design Patterns. What are design patterns? What is a Pattern? Lecture 40: Design Patterns CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki "Each pattern describes a problem which occurs over and over again in our environment, and then describes

More information

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism Subtype, Subtyping vs. Subclassing, Liskov Substitution Principle Outline Subtype polymorphism Subtyping vs. subclassing Liskov Substitution Principle (LSP) Function subtyping Java subtyping Composition:

More information

Programming II. Modularity 2017/18

Programming II. Modularity 2017/18 Programming II Modularity 2017/18 Module? Lecture Outline Evolution and history of programming languages Modularity Example History of Programming Programming Paradigms How and why languages develop? How

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L 2 0 1 5 Introduction Now we ll talk about ways of thinking about design Guidelines for trials in trial and errors Major Design Heuristics

More information

CS 520/620 Advanced Software Engineering Spring February 02, 2016

CS 520/620 Advanced Software Engineering Spring February 02, 2016 CS 520/620 Advanced Software Engineering Spring 2016 February 02, 2016 Logistics Project proposals Elevator pitches on Thursday Deadline for creating groups: 02/03/2016, 11:55pm Deadline for submitting

More information

CS 520/620 Advanced Software Engineering Fall September 27, 2016

CS 520/620 Advanced Software Engineering Fall September 27, 2016 CS 520/620 Advanced Software Engineering Fall 2016 September 27, 2016 Recap Behavioral patterns Strategy pattern Observer Iterator MVC revisited Design patterns commonly used in an MVC architecture Recap:

More information

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP OOP Object oriented programming Polymorphism Encapsulation Inheritance OOP Class concepts Classes can contain: Constants Delegates Events Fields Constructors Destructors Properties Methods Nested classes

More information

Open Closed Principle (OCP)

Open Closed Principle (OCP) Open Closed Principle (OCP) Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhán Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/ SOLID Class Design Principles

More information

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern Think of drawing/diagramming editors ECE450 Software Engineering II Drawing/diagramming editors let users build complex diagrams out of simple components The user can group components to form larger components......which

More information

Modularity!! Guidelines for design! in any programming language!

Modularity!! Guidelines for design! in any programming language! Modularity!! Guidelines for design! in any programming language! 14-1! Modular Software! Software constructed as assemblies of small pieces! 14-2! Modular Software 2! Software constructed as assemblies

More information

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1 Design Principles Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques 2-1 Data Structures Data Structure - A systematic way of organizing and accessing

More information

The Strategy Pattern Design Principle: Design Principle: Design Principle:

The Strategy Pattern Design Principle: Design Principle: Design Principle: Strategy Pattern The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Design

More information

Intro to: Design Principles

Intro to: Design Principles Intro to: Design Principles Pragmatic Programmer: Eliminate Effects Between Unrelated Things design components that are: self-contained, independent, and have a single, well-defined purpose Software Design

More information

Chapter 6. Object- Oriented Programming Part II

Chapter 6. Object- Oriented Programming Part II Chapter 6 Object- Oriented Programming Part II 6: Preview issues surrounding the object creational process the Abstract Factory design pattern private and protected inheritance multiple inheritance comparison

More information

EINDHOVEN UNIVERSITY OF TECHNOLOGY

EINDHOVEN UNIVERSITY OF TECHNOLOGY EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics & Computer Science Exam Programming Methods, 2IP15, Wednesday 17 April 2013, 09:00 12:00 TU/e THIS IS THE EXAMINER S COPY WITH (POSSIBLY INCOMPLETE)

More information

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and

More information

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Summer Term 2018 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Open-Closed Principle Extension: Extending the behavior of a

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar Design Patterns MSc in Communications Software Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

20 Years of. Improve the Design of your Code. Dr Dimitris Dranidis JAVA Meetup Group, Thessaloniki May 2015

20 Years of. Improve the Design of your Code. Dr Dimitris Dranidis JAVA Meetup Group, Thessaloniki May 2015 20 Years of Design Patterns Improve the Design of your Code Dr Dimitris Dranidis JAVA Meetup Group, Thessaloniki May 2015 Dr Dimitris Dranidis Senior Lecturer in Computer Science Department Programme director

More information

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D. Software Design Patterns Jonathan I. Maletic, Ph.D. Department of Computer Science Kent State University J. Maletic 1 Background 1 Search for recurring successful designs emergent designs from practice

More information

Design Pattern- Creational pattern 2015

Design Pattern- Creational pattern 2015 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are created composed represented Encapsulates knowledge about which concrete classes the system uses Hides

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Introduction to Design Patterns

Introduction to Design Patterns Introduction to Design Patterns First, what s a design pattern? a general reusable solution to a commonly occurring problem within a given context in software design It s not a finished design that can

More information

The GoF Design Patterns Reference

The GoF Design Patterns Reference The GoF Design Patterns Reference Version.0 / 0.0.07 / Printed.0.07 Copyright 0-07 wsdesign. All rights reserved. The GoF Design Patterns Reference ii Table of Contents Preface... viii I. Introduction....

More information

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson January 13, 2005 January 18, 2005 1 of 38 Lecture Goals Introduce the basic concepts of object-oriented analysis/design/programming

More information

A few important patterns and their connections

A few important patterns and their connections A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Plan Singleton Factory method Facade and how they are connected. You should understand how to

More information

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade Plan A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Singleton Factory method Facade and how they are connected. You should understand how to

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

Modularity Guidelines for design in any programming language

Modularity Guidelines for design in any programming language Modularity Guidelines for design in any programming language 14-1 Modular Software Software constructed as assemblies of small pieces» Each piece encompasses the data and operations necessary to do one

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism http://en.wikipedia.org/wiki/encapsulation_(object-oriented_programming)

More information

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

An Introduction to Patterns

An Introduction to Patterns An Introduction to Patterns Robert B. France Colorado State University Robert B. France 1 What is a Pattern? - 1 Work on software development patterns stemmed from work on patterns from building architecture

More information

Design Pattern and Software Architecture: IV. Design Pattern

Design Pattern and Software Architecture: IV. Design Pattern Design Pattern and Software Architecture: IV. Design Pattern AG Softwaretechnik Raum E 3.165 Tele.. 60-3321 hg@upb.de IV. Design Pattern IV.1 Introduction IV.2 Example: WYSIWYG Editor Lexi IV.3 Creational

More information

Tuesday, October 4. Announcements

Tuesday, October 4. Announcements Tuesday, October 4 Announcements www.singularsource.net Donate to my short story contest UCI Delta Sigma Pi Accepts business and ICS students See Facebook page for details Slide 2 1 Design Patterns Design

More information

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4 Subtype, Subtyping vs. Subclassing, Liskov Substitution Principle Announcements n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from

More information

Principles of Object-Oriented Design

Principles of Object-Oriented Design Principles of Object-Oriented Design 1 The Object-Oriented... Hype What are object-oriented (OO) methods? OO methods provide a set of techniques for analysing, decomposing, and modularising software system

More information

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns EPL 603 TOPICS IN SOFTWARE ENGINEERING Lab 6: Design Patterns Links to Design Pattern Material 1 http://www.oodesign.com/ http://www.vincehuston.org/dp/patterns_quiz.html Types of Design Patterns 2 Creational

More information

CS 520 Theory and Practice of Software Engineering Fall 2018

CS 520 Theory and Practice of Software Engineering Fall 2018 Today CS 520 Theory and Practice of Software Engineering Fall 208 Object Oriented Design Patterns Recap: Object oriented design principles Design problems & potential solutions Design patterns: What is

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces what is inheritance? examples & Java API examples inheriting a method overriding a method polymorphism Object tostring interfaces Ex: sorting and Comparable interface Inheritance

More information

Self-review Questions

Self-review Questions 7Class Relationships 106 Chapter 7: Class Relationships Self-review Questions 7.1 How is association between classes implemented? An association between two classes is realized as a link between instance

More information

CS152: Programming Languages. Lecture 24 Bounded Polymorphism; Classless OOP. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 24 Bounded Polymorphism; Classless OOP. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 24 Bounded Polymorphism; Classless OOP Dan Grossman Spring 2011 Revenge of Type Variables Sorted lists in ML (partial): type a slist make : ( a -> a -> int) -> a slist

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

More information

COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism

COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism Ibrahim Albluwi Composition A GuitarString has a RingBuffer. A MarkovModel has a Symbol Table. A Symbol Table has a Binary

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

Design Patterns Reid Holmes

Design Patterns Reid Holmes Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book Design Patterns Reid Holmes GoF design patterns $ %!!!! $ "! # & Pattern vocabulary Shared vocabulary

More information

Patterns of learning

Patterns of learning Design patterns Patterns of learning Suppose we want to learn how to play chess. First, we need to learn the basic rules. Then we need to learn the basic strategy/ principles (value of pieces, etc.). To

More information

Object-Oriented Oriented Programming

Object-Oriented Oriented Programming Object-Oriented Oriented Programming Composite Pattern CSIE Department, NTUT Woei-Kae Chen Catalog of Design patterns Creational patterns Abstract Factory, Builder, Factory Method, Prototype, Singleton

More information

Object Oriented Paradigm

Object Oriented Paradigm Object Oriented Paradigm Ming-Hwa Wang, Ph.D. Department of Computer Engineering Santa Clara University Object Oriented Paradigm/Programming (OOP) similar to Lego, which kids build new toys from assembling

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Foundations of Software Engineering Design Patterns -- Introduction

Foundations of Software Engineering Design Patterns -- Introduction Foundations of Software Engineering Design Patterns -- Introduction Fall 2016 Department of Computer Science Ben-Gurion university Based on slides of: Nurit Gal-oz, Department of Computer Science Ben-Gurion

More information

1: Introduction to Object (1)

1: Introduction to Object (1) 1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface

More information

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas What is this class about? While this class is called Design Patterns, there are many other items of critical

More information

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding Java Class Design Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Objectives Implement encapsulation Implement inheritance

More information

Logistics. Final Exam on Friday at 3pm in CHEM 102

Logistics. Final Exam on Friday at 3pm in CHEM 102 Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create

More information

Overview. Elements of Programming Languages. Objects. Self-Reference

Overview. Elements of Programming Languages. Objects. Self-Reference Overview Elements of Programming Languages Lecture 10: James Cheney University of Edinburgh October 23, 2017 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces

More information

Advanced Placement Computer Science. Inheritance and Polymorphism

Advanced Placement Computer Science. Inheritance and Polymorphism Advanced Placement Computer Science Inheritance and Polymorphism What s past is prologue. Don t write it twice write it once and reuse it. Mike Scott The University of Texas at Austin Inheritance, Polymorphism,

More information

Object Model. Object Oriented Programming Spring 2015

Object Model. Object Oriented Programming Spring 2015 Object Model Object Oriented Programming 236703 Spring 2015 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic

More information

Example: Fibonacci Numbers

Example: Fibonacci Numbers Example: Fibonacci Numbers Write a program which determines F n, the (n + 1)-th Fibonacci number. The first 10 Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The sequence of Fibonacci numbers

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

SOFTWARE PATTERNS. Joseph Bonello

SOFTWARE PATTERNS. Joseph Bonello SOFTWARE PATTERNS Joseph Bonello MOTIVATION Building software using new frameworks is more complex And expensive There are many methodologies and frameworks to help developers build enterprise application

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecture 14: Design Workflow Department of Computer Engineering Sharif University of Technology 1 UP iterations and workflow Workflows Requirements Analysis Phases Inception Elaboration

More information

The return Statement

The return Statement The return Statement The return statement is the end point of the method. A callee is a method invoked by a caller. The callee returns to the caller if the callee completes all the statements (w/o a return

More information

CS 251 Intermediate Programming Inheritance

CS 251 Intermediate Programming Inheritance CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?

More information

CSE 70 Final Exam Fall 2009

CSE 70 Final Exam Fall 2009 Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15

More information

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University Idioms and Design Patterns Martin Skogevall IDE, Mälardalen University 2005-04-07 Acronyms Object Oriented Analysis and Design (OOAD) Object Oriented Programming (OOD Software Design Patterns (SDP) Gang

More information

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and

More information

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout 1 Last update: 2 November 2004 Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand Meyer Dr. Karine Arnout 2 Lecture 5: Design patterns Agenda for today 3 Overview Benefits of patterns

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

Need to store a list of shapes, each of which could be a circle, rectangle, or triangle

Need to store a list of shapes, each of which could be a circle, rectangle, or triangle CS112-2012S-23 Abstract Classes and Interfaces 1 23-0: Drawing Example Creating a drawing program Allow user to draw triangles, circles, rectanlges, move them around, etc. Need to store a list of shapes,

More information

Software Design COSC 4353/6353 D R. R A J S I N G H

Software Design COSC 4353/6353 D R. R A J S I N G H Software Design COSC 4353/6353 D R. R A J S I N G H Creational Design Patterns What are creational design patterns? Types Examples Structure Effects Creational Patterns Design patterns that deal with object

More information

Game Architecture Revisited

Game Architecture Revisited Lecture 8 Game Architecture Revisited Recall: The Game Loop 60 times/s = 16.7 ms Update Draw Receive player input Process player actions Process NPC actions Interactions (e.g. physics) Cull non-visible

More information

CPSC 310 Software Engineering. Lecture 11. Design Patterns

CPSC 310 Software Engineering. Lecture 11. Design Patterns CPSC 310 Software Engineering Lecture 11 Design Patterns Learning Goals Understand what are design patterns, their benefits and their drawbacks For at least the following design patterns: Singleton, Observer,

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 3

Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 3 Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Exercise Session 3 Today s Exercise Session Assignment 2 Walkthrough the master solution (your solutions)

More information

CS 520 Theory and Practice of Software Engineering Fall 2017

CS 520 Theory and Practice of Software Engineering Fall 2017 CS 520 Theory and Practice of Software Engineering Fall 2017 OO design patterns September 28, 2017 Logistics Homework 1 deadline: 10/17/2017. Paper reading 1 (Practical guide to statistical tests) deadline:

More information

3D Graphics Programming Mira Costa High School - Class Syllabus,

3D Graphics Programming Mira Costa High School - Class Syllabus, 3D Graphics Programming Mira Costa High School - Class Syllabus, 2009-2010 INSTRUCTOR: Mr. M. Williams COURSE GOALS and OBJECTIVES: 1 Learn the fundamentals of the Java language including data types and

More information

Design Patterns Design patterns advantages:

Design Patterns Design patterns advantages: Design Patterns Designing object-oriented software is hard, and designing reusable object oriented software is even harder. You must find pertinent objects factor them into classes at the right granularity

More information