Week 7 Recap CSE 115 Spring 2007. Not a Holder, but a Proxy be We actually wanted to build a Proxy for our program What is the difference? Holder is a.

Slides:



Advertisements
Similar presentations
Exceptions and Exception Handling Carl Alphonce CSE116.
Advertisements

Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB JavaForum.
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
Exceptions and Exception Handling (1) Carl Alphonce CSE116.
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Road Map Introduction to object oriented programming. Classes
CSE 115 Week 5 February , Monday Announcements Exam 3 today Exam 3 today Lab 3 due this week Lab 3 due this week Exam 4 Monday 2/18 Exam.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
Week 9 Recap CSE 115 Spring Collections “Buckets” that can help us carry around large numbers of objects. “Buckets” that can help us carry around.
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
Week 6 Recap CSE 115 Spring Review We have built a program that uses Association, Composition, Instantiation Dependency, Local Instance Dependency,
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
CSE 115 Week 3 January 28 – February 1, Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.
CSE 115 Week 6 February , Announcements Software Installation Fest – Take 2 Software Installation Fest – Take 2 –Tuesday 2/ –Wednesday.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
CS 106 Introduction to Computer Science I 04 / 21 / 2008 Instructor: Michael Eckmann.
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
Polymorphism CSE 115 Spring 2006 March 6, 8 & 10, 2006.
State,identity and behavior of objects Sem III K.I.R.A.S.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
Polymorphism. Introduction ‘one name multiple forms’ Implemented using overloaded functions and operators Early binding or static binding or static linking.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Lec 19 Array Intro. Agenda Arrays—what are they Declaring Arrays Constructing Arrays Accessing Array cells.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
ECE122 Feb. 22, Any question on Vehicle sample code?
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
Chapter 12 Support for Object oriented Programming.
CSC 313 – Advanced Programming Topics. What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Week101 APCS-AB: Java Miscellaneous Topics: Snippets we missed in Chapters 1-6 of book November 11, 2005.
Introduction to Object-Oriented Programming Lesson 2.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
4.3 Functions. Functions Last class we talked about the idea and organization of a function. Today we talk about how to program them.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Variables and memory addresses
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Week 12 Methods for passing actual parameters to formal parameters.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
OOP Basics Classes & Methods (c) IDMS/SQL News
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Copyright © Jim Fawcett Spring 2017
Object-Oriented Design
Web Design & Development Lecture 9
Interfaces.
Singleton Pattern Command Pattern
Chapter 3: Using Methods, Classes, and Objects
Section 11.1 Class Variables and Methods
Introduction to Object-oriented Program Design
Using local variable without initialization is an error.
Designing for Inheritance
Week 3 Object-based Programming: Classes and Objects
Based on slides by Alyssa Harding & Marty Stepp
DEV-41: The Power of Polymorphism
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Presentation transcript:

Week 7 Recap CSE 115 Spring 2007

Not a Holder, but a Proxy be We actually wanted to build a Proxy for our program What is the difference? Holder is a “bucket” simply holding onto a value. Proxy implements the same interface as the object being used and can react to the same method calls.

Talking to Triangles Wanted the same buttons to talk to triangles as well as bouncing balls. We can change the proxy’s instance variable to have type IBouncer (the interface type) and then we can assign to that variable anything that implements that interface.

Declared Type A variable actually has two types. The first is the declared type, the type given when the variable is first declared. VarType varname;

Actual Type The second is the actual type, the type of the object assigned to the reference. vartype = new OtherType();

How can they be different? Much of the time, the declared type and actual type of a variable are actually the same (as they have been all semester so far). However, the declared type and actual type can be different only when the actual type is a subtype of the declared type.

Subtype? Yes, when a class implements an interface, it becomes a subtype of the interface. Therefore, we will usually see the following: Interface var = new ClassThatImplementsInterface();

What happens in the program? When the declared type of a variable differs from the actual type: The only methods that can be called are those of the declared type. The methods that get executed are those in the actual type.

Polymorphism This is polymorphism. The same “object” responds to the same message in different ways depending on its actual type.

More Patterns! Null Object Pattern Used when we want to express the idea of a “nothing” or “null” object in the system. A null object can be instantiated, but it does nothing if methods are called upon it.

Composite Pattern Creates a structure that allows clients to treat a single object or a group of objects in exactly the same way. In our example, the CompositeShape implements IBouncer and has two instance variables, each whose type is IBouncer.

Composite Pattern We can create a composite of three triangles and two bouncing balls by simple creating a CompositeShape and passing in as parameters an instance of TriangleTriple and an instance of BouncingBallPair.

Composite Pattern Claim: We can make a composite of two sets of TriangleTriples and one set of bouncing balls without making any changes to the CompositeShapes class How can this be done?