Object interaction Creating cooperating objects 3.0.

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 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
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.
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
Improving structure with inheritance Main concepts to be covered Inheritance Subtyping Substitution Polymorphic variables Objects First with Java.
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.
Two Parts of Every ADT An abstract data type (ADT)  is a type for encapsulating related data  is abstract in the sense that it hides distracting implementation.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William.
COS 260 DAY 5 Tony Gauvin.
Understanding class definitions
More about inheritance Exploring polymorphism 5.0.
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.
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.
Creating cooperating objects
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
COS 260 DAY 6 Tony Gauvin.
Further abstraction techniques
Collections and iterators
Presentation transcript:

Object interaction Creating cooperating objects 3.0

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

3 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.

4 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?

5 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. }

6 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. }

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

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

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

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

11 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; }

12 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; }

13 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(); }

14 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(); }

15 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(); }

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

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

18 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();

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

20 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