COS 260 DAY 6 Tony Gauvin.

Slides:



Advertisements
Similar presentations
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
Advertisements

Fields, Constructors, Methods
Object interaction Creating cooperating objects 3.0.
Programming with Objects Creating Cooperating Objects Week 6.
Object Interaction 1 Creating cooperating objects.
Object interaction Creating cooperating objects 5.0.
Object interaction Creating cooperating objects 5.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.
Object Oriented Design: Identifying Objects
Programming Fundamentals 2: Interaction/ F II Objectives – –introduce modularization and abstraction – –explain how an object uses other.
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.
OBJECT INTERACTION CITS1001. Overview Coupling and Cohesion Internal/external method calls null objects Chaining method calls Class constants Class variables.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
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.
1 COS 260 DAY 3 Tony Gauvin. 2 Agenda Questions? 1 st Mini quiz on chap1 terms and concepts –Today In BlackBoard –30 min., M/C and short answer, open.
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.
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.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
1 COS 260 DAY 21 Tony Gauvin. 2 Agenda Questions? 8 th Mini Quiz corrected –Good results 9 Th Mini Quiz Today –40 min covering Chap 9 Assignment 5 Due.
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)
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.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Understanding class definitions Exploring source code 6.0.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
for-each PROS CONS easy to use access to ALL items one-by-one
Objects and Classes CITS1001 week 1.
COS 260 DAY 1 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java Creating cooperating objects
Objects as a programming concept
Agenda Warmup Finish 2.4 Assignments
Operator Overloading; Class string
COS 260 DAY 7 Tony Gauvin.
Object INTERACTION CITS1001 week 3.
Functional Processing of Collections (Advanced)
COS 260 DAY 17 Tony Gauvin.
COS 260 DAY 23 Tony Gauvin.
Objects First with Java
Understanding class definitions
COS 260 DAY 9 Tony Gauvin.
Objects First with Java
COS 260 DAY 13 Tony Gauvin.
Understanding class definitions
COS 260 DAY 19 Tony Gauvin.
COS 260 DAY 11 Tony Gauvin.
COS 260 DAY 11 Tony Gauvin.
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 10 Tony Gauvin.
COS 260 DAY 2 Tony Gauvin.
COS 260 DAY 18 Tony Gauvin.
COS 260 DAY 8 Tony Gauvin.
COS 260 DAY 3 Tony Gauvin.
COS 260 DAY 15 Tony Gauvin.
Creating cooperating objects
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 19 Tony Gauvin.
COS 260 DAY 11 Tony Gauvin.
COS 260 DAY 23 Tony Gauvin.
Creating cooperating objects
COS 260 DAY 14 Tony Gauvin.
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 23 Tony Gauvin.
COS 260 DAY 6 Tony Gauvin.
Presentation transcript:

COS 260 DAY 6 Tony Gauvin

Agenda Questions Assignment 1 DUE Assignment 2 posted Due September 29 Miniquiz 2 on chapter 2 Today 40 min. Open book, open notes, open computer Password “AnneBoleyn’sHusband” Finish Object Interaction (Chap 3)

Primitive types vs. object types Objects First with Java Primitive types vs. object types ObjectType a; ObjectType b; b = a; int a; int b; 32 32 © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling

Quiz: What is the output? int a; int b; a = 32; b = a; a = a + 1; System.out.println(b); Person a; Person b; a = new Person("Everett"); b = a; a.changeName("Delmar"); System.out.println(b.getName()); © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Concepts abstraction modularization classes define types class diagram object diagram object references object types primitive types © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Object interaction Two objects interact when one object calls a method on another. The interaction is usually all in one direction (cf, ‘client’, ‘server’). The client object can ask the server object to do something. The client object can ask for data from the server object. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Object interaction Two NumberDisplay objects store data on behalf of a ClockDisplay object. The ClockDisplay is the ‘client’ object. The NumberDisplay objects are the ‘server’ objects. The client calls methods in the server objects. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Objects First with Java Method calling ‘client’ method public void timeTick() { minutes.increment(); if(minutes.getValue() == 0) { // it just rolled over! hours.increment(); } updateDisplay(); ‘server’ methods internal/self method call © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling

Objects First with Java External method calls General form: object . methodName ( params ) Examples: hours.increment() minutes.getValue() © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling

Objects First with Java Internal method calls No variable name is required: updateDisplay(); Internal methods often have private visibility. Prevents them from being called from outside their defining class. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling

Objects First with Java Internal method /** * Update the internal string that * represents the display. */ private void updateDisplay() { displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue(); } © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling

Method calls NB: A method call on another object of the same type would also be an external call. ‘Internal’ means ‘this object’. ‘External’ means ‘any other object’, regardless of its type. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

The this keyword Used to distinguish parameters and fields of the same name. E.g.: public NumberDisplay(int limit) { this.limit = limit; value = 0; } © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

© 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

© 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

The debugger Useful for gaining insights into program behavior … … whether or not there is a program error. Set breakpoints. Examine variables. Step through code. Exercise 3.44 – 3.49 © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

The debugger © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Objects First with Java Concept summary object creation overloading internal/external method calls debugger © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling