Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
Template Method By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
1 Understanding Inheritance COSC 156 C++ Programming Lecture 8.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns 1.
Assembler Design Options
Programming Pillars Introduction to Object- Oriented Programming.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences University of Scranton October 18, 2015October 18, 2015October 18, 2015.
Inheritance Extending Class Functionality. Polymorphism Review Earlier in the course, we examined the topic of polymorphism. Many times in coding, we.
Pattern Hatching - John Vlissides Pages 85 – 101 Todd Anderson
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Object Oriented Software Development
Mechanisms for Reuse CMPS OOP billed as technology that permits software to be constructed from general-purpose reusable components Two main mechanisms.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Subclassing, pt. 2 Method overriding, virtual methods, abstract classes/methods COMP 401, Fall 2014 Lecture 9 9/16/2014.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
Software Construction and Evolution - CSSE 375 Dealing with Generalization Steve and Shawn Left – In the 1990 movie “The Freshman,” Matthew Broderick,
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Module 9. Dealing with Generalization Course: Refactoring.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
CSCE 240 – Intro to Software Engineering Lecture 3.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Design Patterns: MORE Examples
Sections Inheritance and Abstract Classes
Reuse Separate classes could be developed for all the different objects that are needed in each program. However that would be wasteful. Often many functionalities.
Factory Method Pattern
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Behavioral Design Patterns
Software Design and Architecture
Software Design and Architecture
Testing Object-Oriented Software Concepts and Definitions
Chapter 9 : Assembler Design Options
Factory Method Pattern
Object Oriented Analysis and Design
Jim Fawcett CSE776 – Design Patterns Summer 2003
Week 6 Object-Oriented Programming (2): Polymorphism
Assembler Design Options
Java – Inheritance.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Java Programming, Second Edition
Delegation vs inheritance
Inheritance.
Inheritance and Polymorphism
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Presentation transcript:

Banaras Hindu University

A Course on Software Reuse by Design Patterns and Frameworks

by Dr. Manjari Gupta Department of Computer Science Banaras Hindu University

Lecture 6 Elemental Design Patterns

 proposed by Smith and Stotts  base concepts on which the more complex design patterns are built  a class of problems which are usually considered too obvious to provide a description for  share the same aim with the design patterns, but they are applied to more restricted and specific issues. EDPs

 EDPs are divided into three categories:  Object Element EDPs  Type Relation EDPs  Method Invocation EDPs Categories of EDPs

 CreateObject  AbstractInterface  Retrieve Object Element EDPs

 Inheritance Type Relation EDPs

 Recursion  Conglomeration  Redirect  Delegate  ExtendMethod  RevertMethod  RedirectInFamily  DelegateInFamily  RedirectedRecursion  RedirectInLimitedFamily  DelegateInLimitedFamily  DelegatedConglomeration Method Invocation

 Intent  To provide a common interface for operating on an object type family, but delaying definition of the actual operations to a later time.  Also Known As  Virtual Method, Polymorphism, Defer Implementation Abstract Interface

 Motivation  we run into a situation where we simply cannot provide a meaningful method implementation.  Applicability  Implementation of a method can’t be known until a later date  The interface for that method can be determined  You expect subclasses to handle the functionality of the method Abstract InterfaceCont…

 Structure Abstract InterfaceCont…

 Participants  A  The class type that declares an interface for operation  Collaborations  A defines an interface for a method, that some unknown later subclass will implement. Abstract InterfaceCont…

 Consequences  indicates the absence of a method implementation; instead of showing us to fill in the method,  shows us how to defer the method definition until a later date.  The method is declared, to define the proper interface for our conceptual needs, yet the method body is left undefined. Abstract InterfaceCont…

 Intent  To use all of another classes’ interface, and all or some of its implementation.  Also Known As  IsA Inheritance EDP

 Motivation  the existing methods may provide almost what you need for your new class  it would be highly useful and efficient to reuse the existing class instead of rewriting everything from scratch Inheritance EDPCont…

 Applicability  Two classes are related conceptually, providing the same services.  One of those classes’ implementation or interface is a superset of the other.  or one class is mostly the same as the other. Inheritance EDPCont…

 Structure Inheritance EDPCont…

 Participants  Superclass  Subclass  Collaborations  The Superclass creates a basic set of method interfaces and possibly accompanying method implementations.  Subclass inherits all the interface elements of Superclass, and, by default, all of the implementations as well, which it may choose to override with new implementations. Inheritance EDPCont…

 Consequences  a subclass may not remove a method or data field in most languages  overriding is a waste of good code in the base class  one may not wish to inherit an entire existing class, but instead just small pieces of functionality may be desired. Inheritance EDPCont…

 Intent  Add to, not replace, behaviour in a method of a superclass while reusing existing code.  Also Known As  Extending Super Extend Method

 Motivation  the behaviour of a method needs to be altered or extended  to cut and paste the old code into the new method  tweaking the results as needed  to create a reference to a delegate object with the original behaviour, and then call into it when needed.  Sometimes necessary or desired to subclass directly off of the original class.  two options for extending the original method  cut and paste the old code into the new subclass’ method  ExtendMethod  use Inheritance to provide the mechanism for reuse.  override the original method, but make a call back to the superclass’ implementation of the method. Extend MethodCont…

 Applicability  Existing behaviour of a method needs to be extended but not replaced.  Reuse of code is preferred or necessitated by lack of source code.  Polymorphic behaviour is required. Extend MethodCont…

OriginalBehaviour Operation() ExtendedBehaviour Operation() added behaviour OriginalBehaviour::Operation( ); addedBehaviour Extend Method

 Participants  OriginalBehaviour  Defines interface, contains a method with desired core functionality.  ExtendedBehaviour  Uses interface of OriginalBehaviour, re-implements method as call to base class code with added code and/or behaviour. Extend MethodCont…

 Collaborations  when a subclass overrides a parent class’ method, it is to replace the functionality, but the two method definitions can work together to allow an extension of the behaviour.  ExtendedBehaviour relies on OriginalBehaviour for both interface and core implementation. Extend MethodCont…

 Consequences  overriding of a base class’ method, and  the utilization of that same method  the method Operation in OriginalBehaviour becomes somewhat fragile  Behaviour is extended polymorphically and transparently to clients of OriginalBehaviour. Extend MethodCont…