Object Oriented Design: Identifying Objects

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Fields, Constructors, Methods
Written by: Dr. JJ Shepherd
Constants and Data Types Constants Data Types Reading for this class: L&L,
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Lab 10: Bank Account II Transaction List, error checking & aggregation.
Collections & Loops Chapter 5 Copyright © 2012 Pearson Education, Inc.
Objects First with Java A Practical Introduction using BlueJ
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.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
COMP 110 Introduction to Programming Mr. Joshua Stough October 1, 2007.
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.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
Understanding class definitions Looking inside classes.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Object Oriented Software Development
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Random, Collections & Loops Chapter 5 Copyright © 2012 Pearson Education, Inc.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Chapter 1 Object Orientation: Objects and Classes.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Understanding class definitions
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Written by: Dr. JJ Shepherd
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Chapter 20 Concepts for Object-Oriented Databases Copyright © 2004 Pearson Education, Inc.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
Objects as a programming concept
Objects First with Java A Practical Introduction using BlueJ
Road Map Introduction to object oriented programming. Classes
Objects First with Java
Understanding class definitions
Chapter 3 Introduction to Classes, Objects Methods and Strings
Unit-2 Objects and Classes
COS 260 DAY 2 Tony Gauvin.
COS 260 DAY 3 Tony Gauvin.
Object-Oriented Programming
Programs and Classes A program is made up from classes
Objects First with Java A Practical Introduction using BlueJ
Understanding class definitions
COS 260 DAY 4 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Chapter 3 Introduction to Classes, Objects Methods and Strings
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Presentation transcript:

Object Oriented Design: Identifying Objects

Objects First with Java Review What did we do in the last lab? What did you learn? What classes did we use? What objects did we use? What is the difference between a class and an object? What © David J. Barnes and Michael Kölling

Classes An object is defined by a class A class is the blueprint of an object: A class represents a concept, and an object represents the embodiment (i.e., concrete instance) of that concept The class uses methods to define behaviors of the object Multiple objects can be created from the same class Copyright © 2012 Pearson Education, Inc.

Class = Blueprint One blueprint to create several similar, but different, houses: Copyright © 2012 Pearson Education, Inc.

Let’s play a game: Identify Objects First with Java Let’s play a game: Identify Classes Behaviors/actions Information/data Input/output Break out into groups for angry birds Use the Word document handout for them to fill in classes, data, and behaviors Go and Play the Wii ~15 minutes © David J. Barnes and Michael Kölling

Objects First with Java Basic class structure public class ClassName { Fields Constructors Methods } Three major components of a class: Fields – store data for the object to use Constructors – allow the object to be set up properly when first created Methods – implement the behavior of the object © David J. Barnes and Michael Kölling

Classes/objects (state/behaviors) Car My first car – a maroon Saab 9000 Chair Book Java Software Solutions, 7th Edition Java Software Solutions, 8th Edition Table Student Teacher

Objects First with Java More Identification Think about activities you do everyday What real-world entities do you interact with? What about programs you use? Your phone, laptop/desktop Identify Classes Information/data Behaviors/actions Use the Word document handout for them to fill in classes, data, and behaviors Identify (~4+ minutes) Share/Group (3-4 people; ~6+ minutes) Choose one from the group that everyone is pretty familiar with and write as much detail as you can on the board (~4 minutes) Share/Class (~4+ minutes) © David J. Barnes and Michael Kölling

Objects First with Java Basic class structure public class ClassName { Fields Constructors Methods } Three major components of a class: Fields – store data for the object to use Constructors – allow the object to be set up properly when first created Methods – implement the behavior of the object © David J. Barnes and Michael Kölling

Object-Oriented Programming (OOP) Objects First with Java Object-Oriented Programming (OOP) Objects make it easier to reuse code that others have written Java comes with built-in OO functionality (standard library) Objects commonly represent real-world entities For instance, an object might be a particular employee in a company Each employee object handles the processing and data management related to that employee OO is to programming like the assembly line was to industrialization Explain again, WHY we care about Object-Oriented Programming Purpose – make it easy to reuse code OO is to programming like the assembly line is to industrialization Copyright © 2012 Pearson Education, Inc. © David J. Barnes and Michael Kölling

Objects First with Java Fields Fields store values for an object. They are also known as instance variables. Fields define the state of an object. public class Square { private int x; private int y; private int size; private Color fillColor;   // Further details omitted. } type visibility modifier variable name private int size; Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © David J. Barnes and Michael Kölling

Similar Names for Fields All of these terms can be used interchangeably: Fields Instance Variables Characteristics Data Attributes Properties The values of the fields define the object’s _______ state

Data Types boolean char int long float double String Student (any class) — true, false — a…z,A…Z,[symbols] — integers — larger integers (2x) — floating decimal — larger floating decimal (2x) — characters strung together — defined class

8 Primitive Data Types in Java Four represent integers: byte, short, int, long Two represent floating point numbers (with decimals): float, double One represents single characters: char One represents boolean values: boolean What about other data? It must be defined as a class! Copyright © 2012 Pearson Education, Inc.

Numeric Primitive Data Why so many types to hold numbers? Different sizes affect what values can be stored: Type byte short int long float double Storage 8 bits 16 bits 32 bits 64 bits Min Value -128 -32,768 -2,147,483,648 < -9 x 1018 +/- 3.4 x 1038 with 7 significant digits +/- 1.7 x 10308 with 15 significant digits Max Value 127 32,767 2,147,483,647 > 9 x 1018 Copyright © 2012 Pearson Education, Inc.

Objects First with Java Constructors public Square() { x = 0; y = 0; size = 0; fillColor = Color.blue; } Constructors initialize an object. They have the same name as their class. They store initial values into the fields. They often receive external parameter values for this. Only here as a brief introduction and to reinforce what they saw last class 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 Methods method header/signature return type visibility modifier method name /** * Gets the size of the square. */ parameter list (empty) public int getSize() { return size; } return statement Only here as a brief introduction start and end of method body (block) Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © David J. Barnes and Michael Kölling

What we discussed today … Classes and objects What they are How to identify them How to identify their components Data types

Homework Work on Lab 2 and submit Lab 1 Work with Codingbat exercises Read Chapter 2