Advanced OOD, Patterns and the Strategy Pattern
|
|
- Miranda Howard
- 5 years ago
- Views:
Transcription
1 Advanced OOD, Patterns and the Strategy Pattern 1
2 From Requirements to Object-Oriented Design As a user I want see my nearby friends on the map So that I know who to contact for a spontaneous meet-up Given I am logged in And my location is known When my friends are online And my friends location is known And my friends are near me Then I see them on the map class Friend { Location location(); // null > not-known boolean online(); Bitmap image(); class Friends implements Iterable<Friend> { Friends online(); Friends locationknown(); // > online? 1. Identify the things me (previous user story) friends, friend map (previous, built-in) 2. Identify the messages me.logged-in (previous) friend.location-known friend.location friend.online friend.near(me) friend.image 3. Assemble into classes 4. Right things call right messages (TBD) 2
3 Object-Oriented Typing Rehash: Is-A vs Has-A vs Can-Do Theory of Object-Oriented, III 3
4 Typing and Subtyping: is a In Object-Oriented, it s all about behavior A particular behavior is described by a type Mammalian behavior is the Mammal type Tiger behavior is the Tiger type Because a Tiger always behaves like a Mammal, we say that Tiger is a subtype of Mammal Mammal Feline Canine Tiger House Cat Feline is a subtype of Mammal House Cat is a subtype of Feline s Subtype c means all s s always act like a c but not all c s act like an s All Felines are Mammals But not all Mammals are Felines Means that Feline object will always work wherever a Mammal is needed 4
5 Typing and Subtyping: is a (II) Feline a subtype of Mammal means Mammal a supertype of Feline A supertype variable can hold values of any of its subtypes Mammal Feline Canine Tiger House Cat void petfur(mammal m) { int coarseness = m.furvalue(); Use of a supertype variable like Mammal allows all current and future subtypes of Mammal to be petted petfur will work for Canine subclass Dog when it is added We say that petfur is open for extension 5
6 Three Ways to Declare Subtype in Java Subclass a class class Mammal { class Feline extends Mammal { Feline is a subtype of Mammal Mammal Feline gets all of Mammal s implementation (can override) Subclassing abstract class is similar Can t new an abstract C b/c not all methods implemented abstract class Mammal { class Feline extends Mammal { Feline must implement missing methods of Mammal Abstract class asserts I m a category of thing, not a real thing Interface has no methods implemented Like a totally abstract class interface Cuddly { class HouseCat extends Feline implements Cuddly { 6 Tiger Feline House Cat Canine
7 More on Interfaces In Java, a class can extend just one superclass But a class can implement multiple interfaces interface Cuddly { interface Spotted { class Tabby extends Feline implements Cuddly, Spotted { Means interfaces are much more flexible Can mix in all the supertypes you want Not just a tree of types anymore Feline Mammal Canine Spotted Cuddly Bengal Tiger Tabby 7
8 More on Interfaces, II Not all classes represent a unique type Maybe want another impl of same thing for performance, say Consider two possible impl s of Set class TinySet implements Set { /* linked list */ class BigSet implements Set { /* uses hard disk */ Identical interfaces, input/output behavior > same type One faster for tiny sets, the other faster for big sets Use interfaces for implementation alternatives Since TinySet real subtype, extends would be misleading Since no shared implementation, extends would be misleading 8
9 How represent Feline (and Why)? A. Class B. Abstract Class C. Interface D. Extends Abstract class allows reusing some common implementation among Felines, and yet cannot be new d (instantiated). Interface is a reasonable answer, too, as the sharing might not be too great. Mammal Feline Canine Tiger House Cat 9
10 Interfaces are Central to Java Java Collections Framework Interface Collection methods like add(object) & contains(object) interface List extends Collection interface Set extends Collection Wherever Collection variable appears, allows for a a ListArray or HashSet, etc. Requires no particular implementation Super-flexible code 10
11 Software Design Patterns An Introduction 11
12 Design Patterns, Generally? Consider designing a kitchen Common challenges Need a sink, a stove/oven, a refrigerator, likely a dishwasher Needs counter space, and don t want doors and drawers to collide Need space to stand Common patterns for a solution One-wall, Galley, L-shaped, U-Shaped, Peninsula, Working triangle (Refrigerator, range, sink) Same is true for basic bathroom Tub is 5 x , Sink is 2-2.5, Toilet is Overall minimum dimension is 5 x 7 Tub must go against wall can t cross Don t want to see toilet from door and toilets longer than sinks Standard solution Sink, Toilet, Tub, with door in front of sink. 13
13 Design Patterns, Generally? Bedrooms upstairs; Kitchen, Dining room, main room downstairs Privacy for family spaces, downstairs for entertaining Master bedroom on third floor Privacy for parents or guests One bedroom on lower level Gives privacy from family level Doubles as quiet room near activity, e.g. office, hobby room or den You see the idea Experience leads to an understanding of common challenges And common solutions to those challenges Education leads to learning about these without needing to experience them Learn to spot the common challenges and consider the common patterns for addressing them Also gives us a way of talking about things, e.g. Galley or Working Triangle or Master suite, or Multi-Purpose Den 14
14 Software Design Patterns The same is true of software Common challenges Good ways of addressing these challenges Great way of passing on and receiving experience Common vocabulary and building blocks for conversation Shared expectation about design and code structure Key Elements Name, or we can t talk about it Common, interesting problem Good, exemplar solution A teaching, i.e. what makes the pattern worth learning Consensus, agreement about above and acceptance into vernacular Just like patterns for the design of physical spaces, software design patterns aren t actual solutions to specific real problems, they are ideas that can be applied in many circumstances Idioms are implementations of patterns, i.e. in specific languages 15
15 Software Design Patterns Tricks Identifying common problems Separating common problems from context and arbitrary complexity For example, software design patterns aren t accepted workaround for language specific issues, these are idioms Good solutions, articulating teaching Promulgation and acceptance 16
16 Strategy Pattern Composition + Delegation + Interfaces 17
17 Strategy Pattern Name: Challenge: Solution: Teaching: Strategy Pattern, a.k.a. Policy Pattern Runtime selection of mechanism for implementing a particular behavior, e.g. choosing the best algorithm for the circumstances Define the methods via an interface, that abstracts the behavior and its arguments from the implementation. At runtime, a reference via this interface can be associated with an instance with the proper implementation. Interface references can enable interchangeable strategies, i.e. algorithms, at runtime. 18
18 Shopping Cart, continued class ShoppingCart { DiscountCalculator discountcalculator; int finalpricecents () { return total * (1 discountcalculator.getdiscount()); interface unsigned float DiscountCalculator { unsigned float getdiscount(); class ClubCustomer implements DiscountCalculator { public unsigned float getdiscount() { return (1 MAX_DISCOUNT); class RetailCustomer implements DiscountCalculator { public unsigned float getdiscount() { unsigned float discount = points /POINTS_PER_DPERCENT); return (discount > MAX_DISCOUNT, 1 discount, 1 MAX_DISCOUNT); 19
19 Shopping Cart class ShoppingCart { DiscountCalculator discountcalculator; public ShoppingCart(Customer c) { discount = c.getdiscountcalculator(); int finalpricecents () { return total * (1 discountcalculator.getdiscount()); 20
20 Car Description: What s Wrong? abstract class CarDesc { Color paintcolor(); int wheelbase(); int tiresize(); boolean tireperf(); String tireseason(); /* should be enum */ abstract class SmallCar extends CarDesc { class KiaSoul extends SmallCar { int tiresize() { return 165; boolean tireperf() { return false; String tireseason() { return All ; A. CarDesc and maybe SmallCar should be an interface B. All these classes should implement a Tire interface C. KiaSoul should have a Tire As implemented, KiaSoul only allows one set of values for tire behavior. By adding a Tire via an instance variable and delegating to its function, then all sorts of tires will beas an possible. (See next slide.) 21
21 Widely Used for Algorithm Alternatives 22
10 Design: Which classes must be included?
Decorator Pattern 1 10 Design: Which classes must be included? Story As a user I want a weekend planner so that I can have more fun Scenario Given that I have made a plan When Saturday arrives Then Send
More informationObject Oriented Programming Part II of II. Steve Ryder Session 8352 JSR Systems (JSR)
Object Oriented Programming Part II of II Steve Ryder Session 8352 JSR Systems (JSR) sryder@jsrsys.com New Terms in this Section API Access Modifier Package Constructor 2 Polymorphism Three steps of object
More informationInheritance & Polymorphism. Object-Oriented Programming
Inheritance & Polymorphism Object-Oriented Programming Outline Example Design an inheritance structure IS-A and HAS-A Polymorphism protected access level Rules for overriding the Object class Readings:
More informationObject Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007
Object Fundamentals Part Three Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations
More informationLecture 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 informationCOMP 110/L Lecture 19. Kyle Dewey
COMP 110/L Lecture 19 Kyle Dewey Outline Inheritance extends super Method overriding Automatically-generated constructors Inheritance Recap -We talked about object-oriented programming being about objects
More informationCOMP200 INTERFACES. OOP using Java, from slides by Shayan Javed
1 1 COMP200 INTERFACES OOP using Java, from slides by Shayan Javed Interfaces 2 ANIMAL picture food sleep() roam() makenoise() eat() 3 ANIMAL picture food sleep() roam() makenoise() eat() 4 roam() FELINE
More informationInf1-OP. Classes with Stuff in Common. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein.
Inf1-OP Inheritance UML Class Diagrams UML: language for specifying and visualizing OOP software systems UML class diagram: specifies class name, instance variables, methods,... Volker Seeker, adapting
More informationObject Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009
Object Fundamentals Part Two Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations
More informationCSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community
CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring
More informationInheritance and Substitution (Budd chapter 8, 10)
Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various
More informationInf1-OP. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. March 12, School of Informatics
Inf1-OP Inheritance Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 12, 2018 UML Class Diagrams UML: language for specifying and visualizing OOP software
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
More informationSFPL Simple Floor Plan Language 09/25/2005
SFPL Simple Floor Plan Language 09/25/2005 By: Huang-Hsu Chen (hc2237) Xiao Song Lu(xl2144) Natasha Nezhdanova(nin2001) Ling Zhu(lz2153) Motivation and Introduction Today, many people would like their
More informationObject-Oriented Programming More Inheritance
Object-Oriented Programming More Inheritance Ewan Klein School of Informatics Inf1 :: 2009/10 Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 1 / 45 1 Inheritance Flat Hierarchy
More informationAnnouncements. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Intuition: Type Signature is a Specification.
Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle Announcements HW5 is due today, March 26, 2018 at 11:59:59 pm Exam 2 is next Thursday, March 29, 2018. Practice exam has been
More informationLecture 4: The class hierarchy; static components
1 CS/ENGRD 2110 FALL2017 Lecture 4: The class hierarchy; static components http://cs.cornell.edu/courses/cs2110 Announcements 2 A1 Due Thursday A2 Out Today Where am I? Big ideas so far. 3 Java variables
More informationC09: Interface and Abstract Class and Method
CISC 3120 C09: Interface and Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/28/2017 CUNY Brooklyn College 1 Outline Recap Polymorphism In-class
More informationOutline. 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 informationEncapsulation. Inf1-OOP. Getters and Setters. Encapsulation Again. Inheritance Encapsulation and Inheritance. The Object Superclass
Encapsulation Again Inheritance Encapsulation and Inheritance Inf1-OOP Inheritance and Interfaces Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics March 9, 2015 The Object
More informationInf1-OOP. Inheritance and Interfaces. Ewan Klein, Perdita Stevens. January 12, School of Informatics
Inf1-OOP Inheritance and Interfaces Ewan Klein, Perdita Stevens School of Informatics January 12, 2013 Encapsulation Again Inheritance Encapsulation and Inheritance The Object Superclass Flat vs. Nested
More informationCS/ENGRD 2110 FALL2017. Lecture 4: The class hierarchy; static components
1 CS/ENGRD 2110 FALL2017 Lecture 4: The class hierarchy; static components http://cs.cornell.edu/courses/cs2110 Announcements 2 A0, HW1 due tonight Next week s recitation: loop invariants for ( ) { You
More informationCOMP 250 Fall inheritance Nov. 17, 2017
Inheritance In our daily lives, we classify the many things around us. The world has objects like dogs and cars and food and we are familiar with talking about these objects as classes Dogs are animals
More informationLecture 10: building large projects, beginning C++, C++ and structs
CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 10:
More information2. Classes & Inheritance. Classes. Classes. Éric Tanter Objects and Design in Smalltalk. How do you create objects?
Objects and Design in Smalltalk 2. Classes & Inheritance Éric Tanter etanter@dcc.uchile.cl 1 Classes How do you create objects? Ex-nihilo in prototype-based languages With a class in class-based languages
More informationJava Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.
Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either
More informationObject-Oriented ProgrammingInheritance & Polymorphism
Inheritance Polymorphism Overriding and Overloading Object-Oriented Programming Inheritance & Polymorphism Inf1 :: 2008/09 Inheritance Polymorphism Overriding and Overloading 1 Inheritance Flat Hierarchy
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 informationLesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class
More informationToday. Book-keeping. Inheritance. Subscribe to sipb-iap-java-students. Slides and code at Interfaces.
Today Book-keeping Inheritance Subscribe to sipb-iap-java-students Interfaces Slides and code at http://sipb.mit.edu/iap/java/ The Object class Problem set 1 released 1 2 So far... Inheritance Basic objects,
More informationInheritance & Polymorphism
Inheritance & Polymorphism Procedural vs. object oriented Designing for Inheritance Test your Design Inheritance syntax **Practical ** Polymorphism Overloading methods Our First Example There will be shapes
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 informationPreviously, on Lesson Night... From Intermediate Programming, Part 1
Previously, on Lesson Night... From Intermediate Programming, Part 1 Struct A way to define a new variable type. Structs contains a list of member variables and functions, referenced by their name. public
More informationSoftware Development (cs2500)
Software Development (cs2500) Lecture 31: Abstract Classes and Methods M.R.C. van Dongen January 12, 2011 Contents 1 Outline 1 2 Abstract Classes 1 3 Abstract Methods 3 4 The Object Class 4 4.1 Overriding
More informationWhy use inheritance? The most important slide of the lecture. Programming in C++ Reasons for Inheritance (revision) Inheritance in C++
Session 6 - Inheritance in C++ The most important slide of the lecture Dr Christos Kloukinas City, UoL http://staff.city.ac.uk/c.kloukinas/cpp (slides originally produced by Dr Ross Paterson) Why use inheritance?
More informationSuper-Classes and sub-classes
Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an
More informationIntroduction to Object-Oriented Programming
Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.
More informationMORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011
MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011 1 Goals of the Lecture Continue a review of fundamental object-oriented concepts 2 Overview of OO Fundamentals
More informationInheritance. Finally, the final keyword. A widely example using inheritance. OOP: Inheritance 1
Inheritance Reuse of code Extension and intension Class specialization and class extension Inheritance The protected keyword revisited Inheritance and methods Method redefinition The composite design pattern
More informationRelationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.
CSE 143 Java Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches
More informationNeed 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 informationType Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004
Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...
More informationn 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 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 informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationCSSE 220. Interfaces and Polymorphism. Check out Interfaces from SVN
CSSE 220 Interfaces and Polymorphism Check out Interfaces from SVN Interfaces What, When, Why, How? What: Code Structure used to express operations that multiple class have in common No method implementations
More informationCOMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code
COMPUTER SCIENCE DEPARTMENT PICNIC Welcome to the 2016-2017 Academic year! Meet your faculty, department staff, and fellow students in a social setting. Food and drink will be provided. When: Saturday,
More informationMore OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012
More OO Fundamentals CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012 1 Goals of the Lecture Continue a review of fundamental object-oriented concepts 2 Overview of OO Fundamentals
More informationMore Relationships Between Classes
More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to
More informationInheritance & Polymorphism
E H U N I V E R S I T Y T O H F R G E D I N B U Murray Cole Classifying Things 1 Hierarchies help us to classify things and understand their similarities and differences Some aspects are common to everything
More informationObject- Oriented Design with UML and Java Part I: Fundamentals
Object- Oriented Design with UML and Java Part I: Fundamentals University of Colorado 1999-2002 CSCI-4448 - Object-Oriented Programming and Design These notes as free PDF files: http://www.softwarefederation.com/cs4448.html
More informationC++ Inheritance and Encapsulation
C++ Inheritance and Encapsulation Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance Private vs. Protected Private: private members
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 informationAgenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java
CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda
More informationCSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR
More informationRelationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor
CSC 143 Object & Class Relationships Inheritance Reading: Ch. 10, 11 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog
More informationDocumenting, Using, and Testing Utility Classes
Documenting, Using, and Testing Utility Classes Readings: Chapter 2 of the Course Notes EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Structure of Project: Packages and Classes
More informationImproving structure with inheritance
Objects First With Java A Practical Introduction Using BlueJ Improving structure with inheritance 2.0 Main concepts to be covered Inheritance Subtyping Substitution Polymorphic variables key concepts of
More informationC18a: Abstract Class and Method
CISC 3115 TY3 C18a: Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/31/2018 CUNY Brooklyn College 1 Outline Recap Inheritance and polymorphism Abstract
More informationInheritance. CSE 142, Summer 2002 Computer Programming 1.
Inheritance CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 29-July-2002 cse142-14-inheritance 2002 University of Washington 1 Reading Readings and
More informationLast class. -More on polymorphism -super -Introduction to interfaces
Last class -More on polymorphism -super -Introduction to interfaces Interfaces Sometimes in Java, we will have 2 classes that both share a similar structure, but neither of them is clearly the parent or
More informationLecture 4: The class hierarchy; static components
1 CS/ENGRD 2110 FALL 2018 Lecture 4: The class hierarchy; static components http://cs.cornell.edu/courses/cs2110 Announcements 2 A1 Due Friday A2 Out Today Where am I? Big ideas so far. 3 Java variables
More informationPolymorphism. Arizona State University 1
Polymorphism CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 15 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationCS121/IS223. Object Reference Variables. Dr Olly Gotel
CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors CS121/IS223
More informationObject-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 informationIntroduction to Inheritance
Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationImproving structure with inheritance. Main concepts to be covered. The DoME example. DoME objects. DoME classes. DoME object model
Improving structure with inheritance Main concepts to be covered Inheritance -- adding functionality to classes by extending them Subtyping, as in ArrayList Substitution: if you want a car, either
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationExample: Count of Points
Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;
More information11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures
Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of
More informationObject Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction
Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction Class Interaction There are 3 types of class interaction. One
More informationInheritance. OOP: Inheritance 1
Inheritance Reuse Extension and intension Class specialization and class extension Inheritance The protected keyword revisited Inheritance and methods Method redefinition An widely used inheritance example
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 22 Polymorphism using Interfaces Overview Problem: Can we delay decisions regarding which method to use until run time? Polymorphism Different methods
More informationA Type is a Set of Values. Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values.
Types A Type is a Set of Values Consider the statement: Read Chapter 6 int n; Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values. Also
More informationMore on Inheritance. Interfaces & Abstract Classes
More on Inheritance Interfaces & Abstract Classes Java interfaces A Java interface is used to specify minimal functionality that a client requires of a server. A Java interface contains: method specifications
More informationAdministrivia. Java Review. Objects and Variables. Demo. Example. Example: Assignments
CMSC433, Spring 2004 Programming Language Technology and Paradigms Java Review Jeff Foster Feburary 3, 2004 Administrivia Reading: Liskov, ch 4, optional Eckel, ch 8, 9 Project 1 posted Part 2 was revised
More informationJava and C I. CSE 351 Spring Instructor: Ruth Anderson
Java and C I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Homework 5 Due TONIGHT Wed
More informationCONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17
List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code
More informationob-ject: to feel distaste for something Webster's Dictionary
Objects ob-ject: to feel distaste for something Webster's Dictionary Prof. Clarkson Fall 2017 Today s music: Kung Fu Fighting by CeeLo Green Review Currently in 3110: Advanced topics Futures Monads Today:
More informationComp215: Thinking Generically
Comp215: Thinking Generically Dan S. Wallach (Rice University) Copyright 2015, Dan S. Wallach. All rights reserved. Functional APIs On Wednesday, we built a list of Objects. This works. But it sucks. class
More informationRelationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor
CSE 143 Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog Dog
More informationINHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U
C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes
More informationCREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed
CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?
More informationAssigned Date: August 27, 2014 Due Date: September 7, 2015, 11:59 PM
15440: Distributed Systems Fall 2015 Problem Solving Assignment 1 A Java Programming Preparation for Project 1 Assigned Date: August 27, 2014 Due Date: September 7, 2015, 11:59 PM 1. Warm Up with Some
More informationPolymorphism. Agenda
Polymorphism Lecture 11 Object-Oriented Programming Agenda Classes and Interfaces The Object Class Object References Primitive Assignment Reference Assignment Relationship Between Objects and Object References
More informationObject Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 4 09/03/2009
Object Fundamentals Part Three Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 4 09/03/2009 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations
More informationCreating a New Plan File
1 Tutorial NAME Creating a New Plan File 2 The first step in creating your own design is to open and name a new plan file. 1. From the MENU BAR, select File, New Plan. 2. From the MENU BAR, select File,
More informationSTUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes
STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes Java Curriculum for AP Computer Science, Student Lesson A20 1 STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes INTRODUCTION:
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 informationTopic 7: Algebraic Data Types
Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,
More informationJava and C CSE 351 Spring
Java and C CSE 351 Spring 2018 https://xkcd.com/801/ Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: get_mpg: pushq
More informationSorting. Sorting. Selection sort
Sorting 1 Sorting Given a linear list of comparable objects of the same class (or values of the same type), we wish to sort (or reärrange) the objects in the increasing order. For simplicity, let s just
More informationECE 3574: Dynamic Polymorphism using Inheritance
1 ECE 3574: Dynamic Polymorphism using Inheritance Changwoo Min 2 Administrivia Survey on class will be out tonight or tomorrow night Please, let me share your idea to improve the class! 3 Meeting 10:
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationLab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018 1 Terminology 1 2 Class Hierarchy Diagrams 2 2.1 An Example: Animals...................................
More informationA declaration may appear wherever a statement or expression is allowed. Limited scopes enhance readability.
Scope vs. Lifetime It is usually required that the lifetime of a run-time object at least cover the scope of the identifier. That is, whenever you can access an identifier, the run-time object it denotes
More informationInstance Members and Static Members
Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these
More informationPractice for Chapter 11
Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing
More informationC09: Interface, and Abstract Class and Method
CISC 3120 C09: Interface, and Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 2/28/2018 CUNY Brooklyn College 1 Outline Recap Inheritance and polymorphism
More information