Creating cooperating objects

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

More Sophisticated Behaviour 1 Using library classes to implement more advanced functionality.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
Further abstraction techniques Abstract classes and interfaces 5.0.
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Well-behaved objects Debugging. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Prevention vs Detection.
String Concatenation (operator overloading) 3.0.
Understanding class definitions Looking inside classes 3.0.
More sophisticated behavior Using library classes to implement some more advanced functionality 4.0.
Object interaction Creating cooperating objects 3.0.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
Grouping Objects 1 Introduction to Collections.
Programming with Objects Creating Cooperating Objects Week 6.
Object Interaction 1 Creating cooperating objects.
Understanding class definitions – Part II –. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
1 Reflecting on the ticket machines Their behavior is inadequate in several ways: –No checks on the amounts entered. –No refunds. –No checks for a sensible.
Object interaction Creating cooperating objects 5.0.
Object interaction Creating cooperating objects 5.0.
Further abstraction techniques Abstract classes and interfaces 3.0.
Object Interaction 2 Creating cooperating objects.
Object interaction Creating cooperating objects. 28/10/2004Lecture 3: Object Interaction2 Main concepts to be covered Abstraction Modularization Class.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Programming with Objects Object Interaction (Part 1) Week 9.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
Object Oriented Design: Identifying Objects
Programming Fundamentals 2: Interaction/ F II Objectives – –introduce modularization and abstraction – –explain how an object uses other.
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
OBJECT INTERACTION CITS1001. Overview Coupling and Cohesion Internal/external method calls null objects Chaining method calls Class constants Class variables.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
COS 260 DAY 5 Tony Gauvin.
Understanding class definitions
Chapter 3 Object Interaction.  To construct interesting applications it is not enough to build individual objects  Objects must be combined so they.
1 Opbygning af en Java klasse Abstraktion og modularisering Object interaktion Introduktion til Eclipse Java kursus dag 2.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Grouping objects Arrays. 2 Fixed-size collections The maximum collection size may be pre-determined with an upper limit Array is an fixed-size collection.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Coming up Which methods are where? – Overriding Calling super’s methods Coupling and cohesion.
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
Coming up Inheritance – Code duplication – Super classes – Constructors Polymorphic collections – “Anywhere a super class is, a sub class can go” Casting.
Class definitions CITS1001 week 2.
Objects First with Java Creating cooperating objects
Object INTERACTION CITS1001 week 3.
COS 260 DAY 17 Tony Gauvin.
Objects First with Java
Objects First with Java Transaction List, error checking & aggregation
Understanding class definitions
Objects First with Java A Practical Introduction using BlueJ
More sophisticated behavior
Understanding class definitions
COS 260 DAY 6 Tony Gauvin.
An Introduction to Java – Part II
More about inheritance
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 18 Tony Gauvin.
Exercise 1 Declare a constant of type int called SIZE and initialize it to value 10 Declare two int arrays of size “SIZE” Assume that those int arrays.
Creating cooperating objects
Understanding class definitions
Collections and iterators
Objects First with Java Creating cooperating objects
COS 260 DAY 4 Tony Gauvin.
Objects First with Java Creating cooperating objects
F II 4. Object Interaction Objectives
Comp1202: Inheritance I Super and Sub-classes.
Classes CS 21a: Introduction to Computing I
COS 260 DAY 6 Tony Gauvin.
Eighth step for Learning C++ Programming
Further abstraction techniques
Collections and iterators
Presentation transcript:

Creating cooperating objects Object interaction Creating cooperating objects 1.0

A digital clock Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Abstraction and modularization Abstraction is the ability to ignore details of parts to focus attention on a higher level of a problem. Modularization is the process of dividing a whole into well-defined parts, which can be built and examined separately, and which interact in well-defined ways. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Modularizing the clock display One four-digit display? Or two two-digit displays? Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Implementation - NumberDisplay public class NumberDisplay { private int limit; private int value; Constructor and methods omitted. } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Implementation -ClockDisplay public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; Constructor and methods omitted. } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Object diagram Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Class diagram Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Primitive types vs. object types SomeObject obj; object type int i; primitive type 32 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Primitive types vs. object types SomeObject a; SomeObject b; b = a; int a; int b; 32 32 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Source code: NumberDisplay public NumberDisplay(int rollOverLimit) { limit = rollOverLimit; value = 0; } public void increment() value = (value + 1) % limit; Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Source code: NumberDisplay public String getDisplayValue() { if(value < 10) return "0" + value; else return "" + value; } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Objects creating objects public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; private String displayString; public ClockDisplay() hours = new NumberDisplay(24); minutes = new NumberDisplay(60); updateDisplay(); } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Method calling public void timeTick() { minutes.increment(); if(minutes.getValue() == 0) { // it just rolled over! hours.increment(); } updateDisplay(); Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Internal method /** * Update the internal string that * represents the display. */ private void updateDisplay() { displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue(); } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

ClockDisplay object diagram Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Objects creating objects in class NumberDisplay: public NumberDisplay(int rollOverLimit); formal parameter in class ClockDisplay: hours = new NumberDisplay(24); actual parameter Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Method calls internal method calls updateDisplay(); … private void updateDisplay() external method calls minutes.increment(); Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

object . methodName ( parameter-list ) Method calls (2) object . methodName ( parameter-list ) Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Concepts abstraction modularization classes define types class diagram object diagram object references primitive types object types object creation overloading internal/external method call debugger Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling