COS 260 DAY 6 Tony Gauvin.

Slides:



Advertisements
Similar presentations
Understanding class definitions Looking inside classes 5.0.
Advertisements

Looking inside classes Fields, Constructors & Methods Week 3.
Fields, Constructors, Methods
Road Map Introduction to object oriented programming. Classes
1. 2 Introduction to Methods  Method Calls  Parameters  Return Type  Method Overloading  Accessor & Mutator Methods  Student Class: Revisited.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
String Concatenation (operator overloading) 3.0.
Understanding class definitions Looking inside classes 3.0.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
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.
Programming with Objects Creating Cooperating Objects Week 6.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
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.
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.
Object Interaction 2 Creating cooperating objects.
Understanding class definitions Looking inside classes.
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.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
Object Oriented Design: Identifying Objects
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
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.
Classes CS 21a: Introduction to Computing I First Semester,
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
OBJECT INTERACTION CITS1001. Overview Coupling and Cohesion Internal/external method calls null objects Chaining method calls Class constants Class variables.
COS 260 DAY 5 Tony Gauvin.
Understanding class definitions
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.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
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.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Class Fundamentals BCIS 3680 Enterprise Programming.
Re-Intro to Object Oriented Programming
Creating Your Own Classes
Objects First with Java Creating cooperating objects
Intro To Classes Review
Object INTERACTION CITS1001 week 3.
COS 260 DAY 17 Tony Gauvin.
COS 260 DAY 19 Tony Gauvin.
Introduction to Object-oriented Program Design
Objects First with Java
Understanding class definitions
Understanding class definitions
COS 260 DAY 6 Tony Gauvin.
An Introduction to Java – Part II
COS 260 DAY 11 Tony Gauvin.
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 2 Tony Gauvin.
COS 260 DAY 3 Tony Gauvin.
Creating cooperating objects
Understanding class definitions
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 23 Tony Gauvin.
Object oriented programming (OOP) Lecture No. 6
Chapter 4 Test Review First day
Presentation transcript:

COS 260 DAY 6 Tony Gauvin

Agenda Questions? 2nd Mini quiz results poor Assignment 1 Due All turned in Assignment 2 will be posted soon Will include exercises 3.31 & 3.32 (page 81) Review Class definitions Begin Object Interaction

Class definition revisited Template for a class definition public class ClassName { fields ... constructors … methods … } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Fields Also called instance variables accessibility modifier type fieldname ; private int gradeExam1; Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Constructors Special method type has a header and body visibility modifier ClassName ( parameter list) pararmeter  type, namePara { assignments statements }

Methods Many types two most common are Accessors Mutators All methods has a header and a body Method header is also called a method signature since is most be unique within the class definition Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Accessors used to retrieve state information from an object public type methodName() { return a field } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Mutator Used to change the sate of an object public return_type methodName( parameters) { at least one assignment statement } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Objects First with Java Creating cooperating objects Object interaction Creating cooperating objects 5.0 © David J. Barnes and Michael Kölling

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

Concepts abstraction modularization classes define new types class diagram object diagram object references object types primitive types Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Objects creating objects Objects First with Java 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); … } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © David J. Barnes and Michael Kölling

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

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

Objects First with Java 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 © David J. Barnes and Michael Kölling

Objects First with Java External method call external method calls minutes.increment(); object . methodName ( parameter-list ) Dot notation Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © David J. Barnes and Michael Kölling

Objects First with Java Internal method call internal method calls updateDisplay(); No variable name is required. this could be used as a reference to the invoking object, but not used for method calls. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © 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(); } Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © David J. Barnes and Michael Kölling

Method calls NB: A method call on another object of the same type would be an external call. ‘Internal’ means ‘this object’. ‘External’ means ‘any other object’, regardless of its type.

null null is a special value in Java Object fields are initialized to null by default. You can test for and assign null: private NumberDisplay hours; if(hours != null) { ... } hours = null; Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

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

The debugger Useful for gaining insights into program behavior … … whether or not there is a program error. Set breakpoints. Examine variables. Step through code.

The debugger

Objects First with Java Concept summary object creation overloading internal/external method calls debugger Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © David J. Barnes and Michael Kölling