Object Interaction 1 Creating cooperating objects.

Slides:



Advertisements
Similar presentations
More Sophisticated Behaviour 1 Using library classes to implement more advanced functionality.
Advertisements

Fields, Constructors, Methods
Further abstraction techniques Abstract classes and interfaces 5.0.
Divisibility Rules Page 10 in textbook.
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.
Grouping Objects Arrays and for loops. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Fixed-Size Collections.
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.
Understanding class definitions – Part II –. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
STREAM STREAM A software process The Mañana Principle The Mañana Principle Don’t try to everything at once! Static Methods Static Methods Stateless Utility.
More about inheritance Exploring polymorphism 5.0.
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.
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.
1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts.
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.
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
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.
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.
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
Doing math In java.
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.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
1 COS 260 DAY 18 Tony Gauvin. 2 Agenda Questions? 7 th Mini quiz Graded –Good results 8 th Mini Quiz –Chap 8  Next class Assignment 4 Due Assignment.
Objects First with Java Creating cooperating objects
Object INTERACTION CITS1001 week 3.
Understanding class definitions
COS 260 DAY 6 Tony Gauvin.
COS 260 DAY 16 Tony Gauvin.
Creating cooperating objects
Understanding class definitions
Collections and iterators
Creating cooperating objects
Objects First with Java Creating cooperating objects
Objects First with Java Creating cooperating objects
F II 4. Object Interaction Objectives
Operators In Java Programming By Rajanikanth B.
COS 260 DAY 6 Tony Gauvin.
Further abstraction techniques
Collections and iterators
Presentation transcript:

Object Interaction 1 Creating cooperating objects

This week: Assignment 1 starts

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

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Abstraction and modularisation Abstraction is the ability to ignore details of parts to focus attention on a higher level of a problem. Modularisation 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 Modularising the clock display One four-digit display? Or two two-digit displays? And a bit of glue … :

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 omitted... 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 omitted... methods omitted }

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

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 primitive type 42 int i; SomeObject obj; object type

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Quiz: What is the output? int a; int b; a = 42; b = a; a = a + 1; // has b changed? System.out.println(b); Person a; Person b; a = new Person("Everett"); b = a; a.changeName("Delmar"); // has b changed? System.out.println(b.getName());

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

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Quiz: What is the output? int a; int b; a = 42; b = a; a = a + 1; // has b changed? System.out.println(b); Person a; Person b; a = new Person("Everett"); b = a; a.changeName("Delmar"); // has b changed? System.out.println(b.getName()); no yes

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 The modulo operator The ‘division’ operator ( / ), when applied to int operands, returns the integer result of an integer division. The ‘division’ operator ( / ), when applied to int operands, returns the integer result of an integer division. The ‘modulo’ operator ( % ) returns the integer remainder of an integer division. The ‘modulo’ operator ( % ) returns the integer remainder of an integer division. Example: 17 / 5 = result 3, remainder 2 Example: 17 / 5 = result 3, remainder 2 In Java: 17 / 5 = 3 17 % 5 = 2 In Java: 17 / 5 = 3 17 % 5 = 2

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Quiz What is the result of the expression (8 % 3) What are all possible results of the expression (n % 5) ?

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 Concepts abstraction modularisation primitive types object types class diagram object diagram object references