are most specifically concerned with
|
|
- Megan Blake
- 5 years ago
- Views:
Transcription
1 Observer
2 Behavioral Patterns Behavioral patterns are those patterns that are most specifically concerned with communication between objects
3 Introduction Name Observer Also Known As Dependents, Publish-Subscribe
4 Observer Intent Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically Use the Observer pattern: When an abstraction has two aspects, one dependent on the other. When a change to one object requires changing others, and you don't know how many objects need to be changed When an object should be able to notify other objects without making assumptions about who these objects are.
5 Structure
6 Participants Subject knows its observers. Any number of Observer objects may observe a subject. provides an interface for attaching and detaching Observer objects. Observer defines an updating interface for objects that should be notified of changes in a subject. ConcreteSubject stores state of interest to ConcreteObserver objects. sends a notification to its observers when its state changes. ConcreteObserver maintains a reference to a ConcreteSubject object. stores state that should stay consistent with the subject's. implements the Observer updating interface to keep its state consistent with the subject's.
7 Collaborations
8 SpreadSheet Example
9 SpreadSheet Example How to implement a spreadsheet?
10 Java's Implementation Java API implements a framework for this pattern Java's observer interface is the Observer abstract class in the pattern Java's Observable class is the Subject abstract class in the pattern Class java.util.observable Observable object may have any number of Observers Whenever the Observable instance changes, it notifies all of its observers Notification is done by calling the update() method on all observers. Interface java.util.observer When implemented, this interface allows all classes to be observable by instances of class Observer
11 java.util.observable Methods addobserver(observer) Adds an observer to the observer list. clearchanged() Clears an observable change. countobservers() Counts the number of observers. deleteobserver(observer) Deletes an observer from the observer list. deleteobservers() Deletes observers from the observer list. haschanged() Returns a true boolean if an observable change has occurred.
12 java.util.observable Methods notifyobservers() Notifies all observers if an observable change occurs. notifyobservers(object) Notifies all observers of the specified observable change which occurred. setchanged() Sets a flag to note an observable change. Interface java.util.observer update Called when observers in the observable list need to be updated
13 A Java Example The Classes indicates interface
14 Class Descriptions Counter A Counter can increase or decrease by one. Each time a counter changes value, it notifies its observers of the type of change. IncreaseDectector IncreaseDetector is an observer that observes counters. IncreaseDetector counts the number of times one of its observables increases. It notifies its observers when it changes
15 Class Descriptions CounterButton Abstract class for changing a counter each time the button is pressed IncreaseButton A button that increases a counter each time the button is pressed DecreaseButton A button that decreases a counter each time the button is pressed
16 Class Descriptions CounterView A parent window view that observes a counter. Does nothing with counter. Used as parent for other views. CounterTextView A window for displaying the value of a counter in ASCII. ButtonController A window for changing the value of a counter using IncreaseButton and DecreaseButton. RectangleView Draws a colored rectangle that depends on two counters. One counter is the width of the rectangle, the other counter is the height of the rectangle. The color of rectangle varies with its shape.
17 class Counter /** A counter can increase/decrease by 1. Each time a counter changes value, it notifies its observers of the type of change. */ class Counter extends Observable { public static final String INCREASE = "increase"; public static final String DECREASE = "decrease"; private int count = 0; private String label; public Counter( String label ) { this.label = label; public String label() { return label; public int value() { return count; public String tostring() { return String.valueOf( count ); public void increase() { count++; setchanged(); notifyobservers( INCREASE ); public void decrease() { count--; setchanged(); notifyobservers( DECREASE );
18 class IncreaseDetector /** * IncreaseDetector is an observer that observes counters. *IncreaseDetector counts the number of times one of its * observables increases. */ class IncreaseDetector extends Counter implements Observer { public IncreaseDetector( String label ) { super( label ); public void update( Observable whatchanged, Object message) { if ( message.equals( Counter.INCREASE) ) increase();
19 abstract class CounterButton /** * An abstract class for changing a counter each time the button is pressed */ abstract t class CounterButton tt extends Button { protected Counter count; public CounterButton( String buttonname, Counter count ) { super( buttonname ); this.count = count; public boolean action( Event processnow, Object argument ) { changecounter(); return true; abstract protected void changecounter();
20 class IncreaseButton /** * A button that increases a counter each time it is pressed */ class IncreaseButton extends CounterButton { public IncreaseButton( Counter count ) { super( "Increase", count ); protected void changecounter() { count.increase();
21 class DecreaseButton /** * A button that decreases a counter each time it is pressed */ class DecreaseButton extends CounterButton { public DecreaseButton( Counter count ) { super( "Decrease", count ); protected void changecounter() { count.decrease();
22 class CounterView /** * A parent window view that observes a counter */ class CounterView extends Frame implements Observer { public CounterView( String label, int x, int y, int width, int height ) { settitle( label ); reshape(x, y, width, height ); setlayout( new FlowLayout() ); /** * Redraw the window when an observed counter changes */ public void update(observable counter, Object argument) { repaint();
23 class CounterTextView /** * A window for displaying the value of a counter in ascii */ class CounterTextView tvi extends CounterView { Counter model; public CounterTextView( Counter model, String label, int x, int y, int width, int height ) { super( label, x, y, width, height ); this.model = model; model.addobserver( this ); show(); public void paint( Graphics display ) { int y = bounds().height - 20; int x = 20; display.drawstring( "The value of " + model.label() + " is " + model, x, y );
24 class ButtonController /** * A window for changing the value of a counter */ class ButtonController t extends CounterView { public ButtonController( Counter model, int x, int y, int width, int height ) { super( model.label(), x, y, width, height ); model.addobserver( this ); // show the value of the counter new CounterTextView( model, // buttons to change counter add( new IncreaseButton( model )); add( new DecreaseButton( model )); show(); "Value of " + model.label(), x + width + 5,y, 150, 50);
25 class RectangleView /** * Draws a colored rectangle that depends on two counters. One counter is the width, the other counter is the height ht of the rectangle. The color of rectangle varies with its shape */ class RectangleView extends CounterView { Counter width; Counter height; public RectangleView( Counter rectwidth, Counter rectheight, int x, int y ) { super( "Rectangle", x, y, 150, 150 ); height = rectheight; width = rectwidth; rectwidth.addobserver( ddob this ); rectheight.addobserver( this ); show();
26 class RectangleView Continued public void paint( Graphics display ) { int x = 10; int y = 10; // Magnify value by 5 to get a bigger visual effect int height = 5 * this.height.value(); int width = 5 * this.width.value(); // Determine color. Colors chosen for fun. // The factor of 3 is just to magnify effect of change if (( width >= 0 ) && ( height >= 0 )) display.setcolor( setcolor( new Color( 3*width width, 3*height height, width + height) ); else if (( width < 0 ) && ( height >= 0 )) display.setcolor( Color.pink ); else if (( width >= 0 ) && ( height < 0 )) display.setcolor( setcolor( Color.orange orange ); else if (( width < 0 ) && ( height < 0 )) display.setcolor( Color.red ); display.fillrect(x, y, Math.abs(width), abs(width) Math.abs( abs( height ) );
27 Sample Program class TestButton { public static void main( String args[] ) { Counter x = new Counter( "x" ); Counter y = new Counter( "y" ); IncreaseDetector plus = new IncreaseDetector( "Pluses" ); x.addobserver( plus ); y.addobserver( plus ); new ButtonControler( x, 30, 30, 150, 50 ); new ButtonControler( y, 30, 100, 150, 50 ); new CounterTextView( plus, "# of increases", 30, 170, 150, 50); new RectangleView( x, y, 340, 30 );
28 Sample Program
29 Runtime Object Interaction
30 Consequences Abstract coupling between Subject and Observer Support for broadcast communication Unexpected updates Simple change in subject can cause numerous updates, which can be expensive or distracting Updates can take too long Subject can not perform any work until all observers are done
31 Implementation Issues Mapping subjects(observables) to observers Use list in subject Use hash table Observing more than one subject If an observer has more than one subject how does it know which one changed? Pass information in the update method Dangling references to Deleted Subjects Deleting a subject should not produce dangling references in its observers ers Make the subject notify its observers deleting the observers is not an option
32 Who Triggers the update? Have methods that change the state, trigger update class Counter extends Observable { // some code removed public void increase() { count++; setchanged(); notifyobservers( INCREASE ); If there are several of changes at once, you may not want each change to trigger an update It might be inefficient or cause too many screen updates
33 Who Triggers the update? Have clients call Notify at the right time class Counter extends Observable { // some code removed public void increase() { count++; { Counter pagehits = new Counter(); pagehits.increase(); pagehits.increase(); pagehits.increase(); pagehits.notifyobservers();
34 Make sure Subject is selfconsistent before Notification Important to make sure Subject state is self-consistent before calling Notify, because observers query the subject for its current state in the course of updating their own state This self-consistency rule is easy to violate unintentionally when Subject subclass operations call inherited operations.
35 Make sure Subject is selfconsistent before Notification For example: the notification in the following code sequence is trigged when the subject is in an inconsistent state: void MySubject::Operation (int newvalue) { BaseClassSubject::Operation(newValue); // trigger notification _myinstvar += newvalue; // update subclass state (too late!)
36 Make sure Subject is selfconsistent before Notification You can avoid this pitfall by sending notifications from template methods in abstract Subject classes Template Pattern Define the skeleton of an algorithm in an operation, deferring some steps to subclasses Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure
37 Make sure Subject is selfconsistent before Notification Define a primitive operation for subclasses to override Make Notify the last operation in the template method, which h will ensure that the object is selfconsistent when subclasses override Subject operations void Text::Cut (TextRange r) { ReplaceRange(r); // redefined in subclasses Notify(); Document which Subject operations trigger notifications
38 Specifying modifications of interest explicitly You can improve update efficiency by extending the subject's registration ti interface to allow registering i observers only for specific events of interest. When such an event occurs, the subject informs only those observers that t have registered interest t in that t event. One way to support this uses the notion of aspects for Subject objects. To register interest in particular events, observers are attached to their subjects using void Subject::Attach(Observer*, Aspect& interest); where interest specifies the event of interest. At notification time, the subject supplies the changed aspect to its observers as a parameter to the Update operation. For example: void Observer::Update(Subject*, Aspect& interest);
39 Avoiding observer-specific update protocols the push and pull models Often the subject broadcast additional information about the change. The subject passes this information as an argument to Update. The amount of information may vary widely.
40 Push Model At one extreme, which we call the push model The subject sends observers detailed information about the change, whether they want it or not the push model assumes subjects know something about their observers' needs The push model might make observers less reusable Subject classes make assumptions about Observer classes that might not always be true
41 Pull Model At the other extreme is the pull model the subject sends nothing but the most minimal notification, and observers ask for details explicitly thereafter The pull model emphasizes the subject's ignorance of its observers the pull model may be inefficient Observer classes must ascertain what changed without help from the Subject
42 Adding information about the change push model - add parameters in the update method class IncreaseDetector extends Counter implements Observer { // stuff not shown public void update( Observable whatchanged, Object message) { if ( message.equals( equals( INCREASE) ) increase(); class Counter extends Observable { // some code removed public void increase() { count++; setchanged(); notifyobservers( INCREASE );
43 Adding information about the change pull model - observer asks Subject what happened class IncreaseDetector extends Counter implements Observer { // stuff not shown public void update( Observable whatchanged ) { if ( whatchanged.didyouincrease() didyouincrease() ) increase(); class Counter extends Observable { // some code removed public void increase() { count++; setchanged(); notifyobservers( );
Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of
Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of Computer Science Technische Universität Darmstadt Dr.
More informationOutline. Design Patterns. Observer Pattern. Definitions & Classifications
Outline Design Patterns Definitions & Classifications Observer Pattern Intent Motivation Structure Participants Collaborations Consequences Implementation 1 What is a Design Pattern describes a problem
More informationObserver Pattern. CS580 Advanced Software Engineering October 31, Yu Sun, Ph.D.
Observer Pattern CS580 Advanced Software Engineering http://cs356.yusun.io October 31, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Announcements Quiz 5 Singleton Pattern Abstract Factory Pattern
More informationObject-Oriented Oriented Programming
Object-Oriented Oriented Programming Visitor Pattern Observer Pattern CSIE Department, NTUT Woei-Kae Chen Visitor Pattern Visitor Pattern Behavioral pattern Visitor: Intent Represent an operation to be
More informationIT 313 Advanced Application Development
Page 1 of 10 IT 313 Advanced Application Development Final Exam -- March 13, 2016 Part A. Multiple Choice Questions. Answer all questions. You may supply a reason or show work for partial credit. 5 points
More informationDesign Patterns. Definition of a Design Pattern
Design Patterns Barbara Russo Definition of a Design Pattern A Pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem,
More informationModellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico
Modellistica Medica Maria Grazia Pia INFN Genova Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico 2002-2003 Lezione 9 OO modeling Design Patterns Structural Patterns Behavioural Patterns
More informationENGLISH Page 1 of 6. EXAM IN COURSE TDT4100 Object-Oriented Programming / IT1104 Programming, Advanced Course. Tuesday 29. Mai
ENGLISH Page 1 of 6 NTNU Norges teknisk-naturvitenskapelige universitet Fakultet for informasjonsteknologi, matematikk og elektroteknikk Institutt for datateknikk og informasjonsvitenskap EXAM IN COURSE
More informationDesign Patterns. GoF design patterns catalog
Design Patterns GoF design patterns catalog OMT notations - classes OMT notation - relationships Inheritance - triangle Aggregation - diamond Acquaintance keeps a reference solid line with arrow Creates
More informationINHERITANCE. Spring 2019
INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose
More information6 The MVC model. Main concepts to be covered. Pattern structure. Using design patterns. Design pattern: Observer. Observers
Main concepts to be covered 6 The MVC model Design patterns The design pattern The architecture Using design patterns Inter-class relationships are important, and can be complex. Some relationship recur
More informationObserver / Template Methods (cont.) Comp-304 : Observer / Template Methods (cont.) Lecture 27
Observer / Template Methods (cont.) Comp-304 : Observer / Template Methods (cont.) Lecture 27 Alexandre Denault Original notes by Hans Vangheluwe Computer Science McGill University Fall 2007 Questions?
More informationDesign Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern.
Proxy : Motivation Design s 2 It is 3pm. I am sitting at my 10Mbps connection and go to browse a fancy web page from the US, This is prime web time all over the US. So I am getting 100kbps What can you
More informationGood Luck! CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none. Student Number: Lecture Section: L0101. Instructor: Horton
CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none Student Number: Last Name: Lecture Section: L0101 First Name: Instructor: Horton Please fill out the identification section above as well
More informationSolution register itself
Observer Pattern Context: One object (the Subject) is the source of events. Other objects (Observers) want to know when an event occurs. Or: several objects should be immediately updated when the state
More informationApply a Design Pattern
Apply a Design Pattern Objectives After completing this lab, you will be able to: Given Apply a design pattern to a model. Transform UML classes to Java classes. Explore the transformation results. No
More informationLast Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005
1 Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/6448 - Spring Semester, 2005 2 Last Lecture Design Patterns Background and Core Concepts Examples
More informationCOSC 3351 Software Design. Design Patterns Behavioral Patterns (I)
COSC 3351 Software Design Design Patterns Behavioral Patterns (I) Spring 2008 Purpose Creational Structural Behavioral Scope Class Factory Method Adapter(class) Interpreter Template Method Object Abstract
More information02. OBSERVER PATTERN. Keep your Objects in the know. Don t miss out when something interesting happens
BIM492 DESIGN PATTERNS 02. OBSERVER PATTERN Keep your Objects in the know Don t miss out when something interesting happens Congrats! Your team has just won the contract to build Weather-O-Rama, Inc. s
More informationInheritance. Lecture 11 COP 3252 Summer May 25, 2017
Inheritance Lecture 11 COP 3252 Summer 2017 May 25, 2017 Subclasses and Superclasses Inheritance is a technique that allows one class to be derived from another. A derived class inherits all of the data
More informationCSE 331 Software Design and Implementation. Lecture 16 Callbacks and Observers
CSE 331 Software Design and Implementation Lecture 16 Callbacks and Observers Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 6 due Thursday 8/2 Homework 7 due Thursday 8/2 Callbacks The
More informationLaboratorio di Tecnologie dell'informazione
Laboratorio di Tecnologie dell'informazione Ing. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Design pattern Observer Some motivations In many programs, when a object changes
More informationOutline. Observer Pattern: Pitfalls. Observer Applications
Outline Observer Pattern: Pitfalls NotifyObservers Invocation Problem M:N Problem ConcurrentModificationException Problem Cyclic Dependency Problem Causality of State Changes Problem Memory Management
More informationEXAMPLE ANSWERS. EXAM IN COURSE TDT4100 Object-Oriented Programming / IT1104 Programming, Advanced Course. Tuesday 29. Mai
ENGLISH Page 1 of 15 NTNU Norges teknisk-naturvitenskapelige universitet Fakultet for informasjonsteknologi, matematikk og elektroteknikk Institutt for datateknikk og informasjonsvitenskap EXAMPLE ANSWERS
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationCSE 331 Software Design and Implementation. Lecture 17 Events, Listeners, Callbacks
CSE 331 Software Design and Implementation Lecture 17 Events, Listeners, Callbacks Zach Tatlock / Winter 2016 The limits of scaling What prevents us from building huge, intricate structures that work perfectly
More informationCSE 331. Model/View Separation and Observer Pattern
CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/ 1 Model and
More informationEvent-driven Programming, Separation of Concerns, the Observer pattern and the JavaFX Event Infrastructure
Java GUIs in JavaFX Event-driven Programming, Separation of Concerns, the Observer pattern and the JavaFX Event Infrastructure 1 GUIs process inputs and deliver outputs for a computing system Inputs Click
More informationMaking New instances of Classes
Making New instances of Classes NOTE: revised from previous version of Lecture04 New Operator Classes are user defined datatypes in OOP languages How do we make instances of these new datatypes? Using
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationDesign 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 informationUppsala University. Assignment 3. Separation into Model-View TableModel ListModel ( multiple inheritance or adapter) Renderer (delegation)
ToDo-list Assignment 3 Separation into Model-View TableModel ListModel ( multiple inheritance or adapter) Renderer (delegation) A new component Extend Swing with your own design Theme Modify look&feel
More informationJava Generics Chapter 9: Design patterns. /** * INF329 - Spring 2007 * Presented by Stian Stokkenes * */ {
Java Generics Chapter 9: Design patterns /** * INF329 - Spring 2007 * Presented by Stian Stokkenes * stian@stokkenes.de */ { Chapter 9 - Design patterns Goal: Show how design patterns can take advantage
More informationPackage org.nongnu.multigraph
Package org.nongnu.multigraph Page 1 of 130 org.nongnu.multigraph.adjacencymatrix org.nongnu.multigraph Class AdjacencyMatrix java.lang.object +-org.nongnu.multigraph.adjacencymatrix public class AdjacencyMatrix
More informationJava 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 informationA reusable design concept
References: Xiaoping Jia, Object-Oriented Software Development Using Java;Douglas C.Schmidt, Design Pattern Case Studies with C++;Bruce E.Wampler,The Essence of Object-Oriented Programming with Java and
More informationLast Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns
Lecture 26: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Last Lecture Design Patterns Background and Core Concepts Examples Singleton,
More information2/17/04 Doc 8 Adapter & Strategy slide # 1
2/17/04 Doc 8 Adapter & Strategy slide # 1 CS 635 Advanced Object-Oriented Design & Programming Spring Semester, 2004 Doc 8 Adapter & Strategy Contents Adapter...2 Motivating Adapter...2 Adapter...6 Consequences...10
More informationTO DO: Create a new class which adds statistics to the dice. NOTE: Don t forget to run regression tests
TO DO: Create a new class which adds statistics to the dice This class should add functionality to store the roll frequencies. You should implement a validation test (as well as running unit tests) as
More informationSingleton Pattern Creational
Singleton Pattern Creational Intent» Ensure a class has only one instance» Provide a global point of access Motivation Some classes must only have one instance file system, window manager Applicability»
More informationDesign 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 informationTopics 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 informationLecture 5. Lecture
this GUI Example: SignalGUI Orphans D0010E Object- Oriented Programming and Design Model- View- Control Example: Counter Observer Recursive References Design PaOerns - Håkan Jonsson 1 1 About dynamic objects
More informationDesign patterns for graphical user interface applications
Design patterns for graphical user interface applications Prof.Asoc. Alda Kika Department of Informatics Faculty of Natural Sciences University of Tirana Outline Pattern Concept Design pattern in computer
More informationDesign Patterns. Observer Pattern*
Design Patterns Observer Pattern* ebru@hacettepe.edu.tr ebruakcapinarsezer@gmail.com http://yunus.hacettepe.edu.tr/~ebru/ @ebru176 Kasım 2017 *revised from Observer Pattern, OOA&D, Rubal Gupta, CSPP, Winter
More informationCSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3:
PROGRAMMING ASSIGNMENT 3: Read Savitch: Chapter 7 Programming: You will have 5 files all should be located in a dir. named PA3: ShapeP3.java PointP3.java CircleP3.java RectangleP3.java TriangleP3.java
More informationComp-304 : Object-Oriented Design What does it mean to be Object Oriented?
Comp-304 : Object-Oriented Design What does it mean to be Object Oriented? What does it mean to be OO? What are the characteristics of Object Oriented programs (later: OO design)? What does Object Oriented
More informationInheritance. Notes Chapter 6 and AJ Chapters 7 and 8
Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Interface Abstract data types Version of January 26, 2013 Abstract These lecture notes are meant
More informationObject-Oriented Design
Object-Oriented Design Lecture 20 GoF Design Patterns Behavioral Department of Computer Engineering Sharif University of Technology 1 GoF Behavioral Patterns Class Class Interpreter: Given a language,
More informationCOS226 - 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 informationSOFTWARE DESIGN COSC 4353 / Dr. Raj Singh
SOFTWARE DESIGN COSC 4353 / 6353 Dr. Raj Singh UML - History 2 The Unified Modeling Language (UML) is a general purpose modeling language designed to provide a standard way to visualize the design of a
More informationCS 160: Interactive Programming
CS 160: Interactive Programming Professor John Canny 3/8/2006 1 Outline Callbacks and Delegates Multi-threaded programming Model-view controller 3/8/2006 2 Callbacks Your code Myclass data method1 method2
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationObjects, Subclassing, Subtyping, and Inheritance
Objects, Subclassing, Subtyping, and Inheritance Brigitte Pientka School of Computer Science McGill University Montreal, Canada In these notes we will examine four basic concepts which play an important
More informationAP CS Unit 6: Inheritance Notes
AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything
More informationDay 4. COMP1006/1406 Summer M. Jason Hinek Carleton University
Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information
More information+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.
+ Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create
More informationStudying software design patterns is an effective way to learn from the experience of others
Studying software design patterns is an effective way to learn from the experience of others 1 Parties have different ways of presenting the results. Presentation of results Coupling Computation of results
More informationBuilding Graphical User Interfaces with the MVC Pattern
Building Graphical User Interfaces with the MVC Pattern Joseph Bergin Pace University jbergin@pace.edu The Model View Controller pattern was invented in a Smalltalk context for decoupling the graphical
More informationF I N A L E X A M I N A T I O N
Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student
More informationProgramming 2. Inheritance & Polymorphism
Programming 2 Inheritance & Polymorphism Motivation Lame Shape Application public class LameShapeApplication { Rectangle[] therects=new Rectangle[100]; Circle[] thecircles=new Circle[100]; Triangle[] thetriangles=new
More informationM301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism
Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze
More informationCOMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed
1 1 COMP200 INHERITANCE OOP using Java, from slides by Shayan Javed 2 Inheritance Derive new classes (subclass) from existing ones (superclass). Only the Object class (java.lang) has no superclass Every
More informationInheritance, and Polymorphism.
Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to
More informationLOG6306 : Études empiriques sur les patrons logiciels
LOG6306 : Études empiriques sur les patrons logiciels Foutse Khomh The Abstract Factory DP This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 3.0 Unported License Context
More informationCISC 1600 Lecture 3.1 Introduction to Processing
CISC 1600 Lecture 3.1 Introduction to Processing Topics: Example sketches Drawing functions in Processing Colors in Processing General Processing syntax Processing is for sketching Designed to allow artists
More informationDesign Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011
Design Patterns Lecture 2 Manuel Mastrofini Systems Engineering and Web Services University of Rome Tor Vergata June 2011 Structural patterns Part 2 Decorator Intent: It attaches additional responsibilities
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes
More informationDesign Patterns. Produced by. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology
Design Patterns 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 Template Method Design
More informationModule dependences and decoupling (Events, listeners, callbacks)
Module dependences and decoupling (Events, listeners, callbacks) CSE 331 University of Washington Michael Ernst The limits of scaling What prevents us from building huge, intricate structures that work
More informationJava Programming Lecture 6
Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components
More informationComputer Science 210: Data Structures
Computer Science 210: Data Structures Summary Today writing a Java program guidelines on clear code object-oriented design inheritance polymorphism this exceptions interfaces READING: GT chapter 2 Object-Oriented
More informationChapter 6: Inheritance
Chapter 6: Inheritance EECS 1030 moodle.yorku.ca State of an object final int WIDTH = 3; final int HEIGTH = 4; final int WEIGHT = 80; GoldenRectangle rectangle = new GoldenRectangle(WIDTH, HEIGHT, WEIGHT);
More informationChapter 7 Applets. Answers
Chapter 7 Applets Answers 1. D The drawoval(x, y, width, height) method of graphics draws an empty oval within a bounding box, and accepts 4 int parameters. The x and y coordinates of the left/top point
More informationITI 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 informationNull Object Design Pattern. Null Object Design Pattern. An Example: Authentication in HTTP. Intent
Null Object Design Pattern Null Object Design Pattern Intent Encapsulate the implementation decisions of how to do nothing and hide those details from clients Replace a null-checking (i.e., if statement)
More informationLab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in
Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the
More information(Refer Slide Time: 02:01)
Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #29 Java Applets Part: 2 In this lecture we shall be continuing
More informationProduced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar
Design Patterns MSc in Computer Science 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 informationSoftware Engineering I (02161)
Software Engineering I (02161) Week 10 Assoc. Prof. Hubert Baumeister DTU Compute Technical University of Denmark Spring 2016 Last Time Project Planning Non-agile Agile Refactoring Contents Basic Principles
More informationInheritance 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 informationEECS 1001 and EECS 1030M, lab 01 conflict
EECS 1001 and EECS 1030M, lab 01 conflict Those students who are taking EECS 1001 and who are enrolled in lab 01 of EECS 1030M should switch to lab 02. If you need my help with switching lab sections,
More informationITI 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 informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationSSJ User s Guide. Package stat Tools for Collecting Statistics. Version: December 21, 2006
SSJ User s Guide Package stat Tools for Collecting Statistics Version: December 21, 2006 CONTENTS 1 Contents Overview........................................ 2 StatProbe........................................
More informationChapter 9 Inheritance
Chapter 9 Inheritance I. Scott MacKenzie 1 Outline 2 1 What is Inheritance? Like parent/child relationships in life In Java, all classes except Object are child classes A child class inherits the attributes
More informationCS1150 Principles of Computer Science Objects and Classes
CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8
More informationJava and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1
Java and OOP Part 3 Extending classes OOP in Java : W. Milner 2005 : Slide 1 Inheritance Suppose we want a version of an existing class, which is slightly different from it. We want to avoid starting again
More informationProgramming in the Large II: Objects and Classes (Part 2)
Programming in the Large II: Objects and Classes (Part 2) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen
More informationWhat 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 informationInheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8
Inheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8 1 Preconditions and Inheritance precondition what the method assumes to be true about the arguments passed to it inheritance (is-a) a subclass
More informationSDC 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 information24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini
24. Inheritance Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Superclasses and Subclasses Inheritance
More informationName Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?
1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type
More informationindex.pdf January 21,
index.pdf January 21, 2013 1 ITI 1121. Introduction to Computing II Circle Let s complete the implementation of the class Circle. Marcel Turcotte School of Electrical Engineering and Computer Science Version
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
More informationOverriding Variables: Shadowing
Overriding Variables: Shadowing We can override methods, can we override instance variables too? Answer: Yes, it is possible, but not recommended Overriding an instance variable is called shadowing, because
More informationInheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L
Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive
More information