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.
Fields, Constructors, Methods
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.
Improving structure with inheritance
More sophisticated behaviour Using library classes to implement some more advanced functionality.
Well-behaved objects Debugging. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Prevention vs Detection.
Objects First with Java A Practical Introduction using BlueJ
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 2 Collections and the for-each loop Collections and the while loop.
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.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.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.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
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.
Improving structure with inheritance Main concepts to be covered Inheritance Subtyping Substitution Polymorphic variables Objects First with Java.
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 2.0.
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.
Grouping objects Collections and iterators Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
COS 260 DAY 5 Tony Gauvin.
Understanding class definitions
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Chapter 3 Object Interaction.  To construct interesting applications it is not enough to build individual objects  Objects must be combined so they.
OOPDA Intro 5.0. Topics Website and Syllabus Rowan VPN and H:drive BlueJ application and projects Programming Style (Appendix J) Javadoc (Appendix I)
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 Grouping objects Collections and iterators 1.0.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
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.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
1 COS 260 DAY 22 Tony Gauvin. 2 Agenda Questions? 9 th Mini Quiz corrected –Good results Assignment 5 Not corrected yet Assignment 6 Posted (one more)
Objects and Classes CITS1001 week 1.
Objects First with Java Creating cooperating objects
Object INTERACTION CITS1001 week 3.
Objects First with Java
Understanding class definitions
COS 260 DAY 6 Tony Gauvin.
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 3 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Understanding class definitions
Collections and iterators
Creating cooperating objects
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
Objects First with Java A Practical Introduction using BlueJ
COS 260 DAY 6 Tony Gauvin.
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