Programming with Objects Creating Cooperating Objects Week 6.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Looking inside classes Fields, Constructors & Methods Week 3.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Object-Oriented PHP (1)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object interaction Creating cooperating objects 3.0.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Object Interaction 1 Creating cooperating objects.
Object interaction Creating cooperating objects 5.0.
Object interaction Creating cooperating objects 5.0.
Introduction to Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically.
Object Interaction 2 Creating cooperating objects.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object interaction Creating cooperating objects. 28/10/2004Lecture 3: Object Interaction2 Main concepts to be covered Abstraction Modularization Class.
Object-Oriented Analysis and Design
Programming with Objects Object Interaction (Part 1) Week 9.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
Object Oriented Software Development
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Object Oriented Design: Identifying Objects
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Programming Fundamentals 2: Interaction/ F II Objectives – –introduce modularization and abstraction – –explain how an object uses other.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
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.
Data Structures Using C++1 Chapter 1 -Software Engineering Principles -ADT and Classes.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
COS 260 DAY 5 Tony Gauvin.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
Chapter 3 Object Interaction.  To construct interesting applications it is not enough to build individual objects  Objects must be combined so they.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
1 Opbygning af en Java klasse Abstraktion og modularisering Object interaktion Introduktion til Eclipse Java kursus dag 2.
OOP Review CS 124.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Classes, Interfaces and Packages
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.
OOP Basics Classes & Methods (c) IDMS/SQL News
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Chapter 11 An introduction to object-oriented design.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Objects First with Java Creating cooperating objects
The Object-Oriented Thought Process Chapter 1
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object INTERACTION CITS1001 week 3.
ATS Application Programming: Java Programming
COS 260 DAY 6 Tony Gauvin.
Defining Classes and Methods
Chapter 10 Thinking in Objects
IFS410: Advanced Analysis and Design
Week 4 Object-based Programming (2) Classes and Objects: A Deeper Look
Creating cooperating objects
Creating cooperating objects
Objects First with Java Creating cooperating objects
Object-Oriented Programming
Objects First with Java Creating cooperating objects
F II 4. Object Interaction Objectives
Defining Classes and Methods
Defining Classes and Methods
COS 260 DAY 6 Tony Gauvin.
Programming For Big Data
Presentation transcript:

Programming with Objects Creating Cooperating Objects Week 6

Abstraction & Modularisation Object Diagrams & Class Diagrams Primitive Types & Object Types Objects creating other Objects Calling methods on Objects Programming with Objects CONCEPTS COVERED THIS WEEK

What is OO? Mirrors the real world Classes: –‘Types’ or blueprints –‘Encapsulating’ data and actions (methods) encapsulation –Some parts hidden from the outside world data hiding

Objects Objects: –instances (or variables) of a class –once ‘instantiated’ (created) exist until they are destroyed –communicate with each other and the outside world by messages

Classes A class is a blueprint or template. We can then create as many objects of the class as we need Think of each of these objects as having their own set of data and methods.

Class / Object Relationships ASSOCIATION -one object uses another object. Key word: uses. –(a car uses a car park.) AGGREGATION/COMPOSITION -one object may be made up of other objects. Key word: has a. –(e.g. CAR has a STEERING WHEEL, ENGINE..) INHERITANCE -an object inherits the properties of another. Key word: is a –(HATCHBACK is a type of CAR, its superclass)

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 a set of well-defined parts, where each part can be built and tested separately, and where each part only interacts with other parts in well-defined ways. Programming with Objects ABSTRACTION & MODULARISATION

It is an object that is made up of other objects! Wheels, Seats, Chassis, Exhaust, Steering Wheel, etc, etc... This car is a Complex Object And… a wheel itself is also a complex object! Tire, Trim, Hub Cap, etc, etc... ABSTRACTION & MODULARISATION Object Model

MODULARISATION Object Model Team 1 works on producing the Engine Design: Team 2 works on producing the Seat Design: Team 3 works on producing the Wheel Design: Team 3a works on producing the Tire Design:

Programming with Objects ABSTRACTION & MODULARISATION A digital clock

Programming with Objects ABSTRACTION & MODULARISATION Modularising the clock display One four-digit display? Or two two-digit displays?

Programming with Objects Implementation - NumberDisplay public class NumberDisplay { private int limit; private int value; // Constructor and methods // omitted. }

Programming with Objects Implementation - ClockDisplay public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; // Constructor and methods // omitted. }

Programming with Objects OBJECT DIAGRAM

Programming with Objects CLASS DIAGRAM

Programming with Objects PRIMITIVE TYPES & OBJECT TYPES 32 object type primitive type SomeClass obj; int i; (‘pointer’ to the actual object)

Primitive data types contain values 6 int i = float x = 2.5f A char grade = ‘A’ The “=“ symbol here means “put into (assign value to) box” Programming with Objects VARIABLES OF PRIMITIVE TYPES

Programming with Objects PRIMITIVE TYPES byte primitive value age byte age = 39;

Object types contain references to objects “Mark” String name = “Mark”; name Person object Person mark = new Person( ); mark The “=“ symbol here means “point to the box” Programming with Objects VARIABLES OF OBJECT TYPES

Programming with Objects OBJECT TYPES Person object reference value mark Person mark = new Person(); mark.setName(“Mark Campbell”); mark.setJob(“Lecturer”); mark.setAge(39);

Programming with Objects PRIMITIVE TYPES & OBJECT TYPES 32 SomeClass a; int a; SomeClass b; 32 int b; b = a; SomeClass Object

BlueJ Demonstration A look at object interaction in the ClockDisplay class

Modulo (or modulus) operator The % operator gives the remainder of a division result = 10 % 3; assigns a value of 1 to result result = 15 % 6; result = 19 % 11;

Programming with Objects Source Code - NumberDisplay public NumberDisplay(int rollOverLimit) { limit = rollOverLimit; value = 0; } public void increment() { value = (value + 1) % limit; }

Programming with Objects Source Code - NumberDisplay public String getDisplayValue() { if(value < 10) return "0" + value; else return "" + value; }

Programming with Objects Source Code (Object Creation) - ClockDisplay public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; private String displayString; public ClockDisplay() { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); updateDisplay(); }

Programming with Objects Source Code (Method Calling) - ClockDisplay public void timeTick() { minutes.increment(); if(minutes.getValue() == 0) { // it just rolled over! hours.increment(); } updateDisplay(); }

Programming with Objects Source Code (Internal Method) - ClockDisplay /** * Update the internal string that * represents the display. */ private void updateDisplay() { displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue(); }

Programming with Objects INTERNAL/EXTERNAL METHOD CALLS Internal Method Calls: updateDisplay();... private void updateDisplay() {... } External Method Calls: minutes.increment();

Programming with Objects INTERNAL/EXTERNAL METHOD CALLS object.methodName(parameter-list) minutes.increment(); EXAMPLES: hours.getDisplayValue(); minutes.getDisplayValue(); updateDisplay(); Object identifier No object identifier is required for internal method calls.

Programming with Objects OBJECT DIAGRAM (ClockDisplay)

Programming with Objects OBJECTS CREATING OBJECTS hours = new NumberDisplay(24); public NumberDisplay(int rollOverLimit); ClockDisplay: NumberDisplay: formal parameter actual parameter

Required Reading Objects First With Java – A Practical Introduction using BlueJ Related reading for this lecture Read Chapter 3 (pp 56 – 75)