Object Oriented Design: Identifying Objects

Similar documents
Lab: PiggyBank. Defining objects & classes

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Ticket Machine Project(s)

Objects First with Java A Practical Introduction using BlueJ

Objects First with Java A Practical Introduction using BlueJ

Object-Oriented Programming Concepts

Inheritance. Improving Structure with Inheritance. Dr. Siobhán Drohan Mairead Meagher. Produced by:

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005

UNDERSTANDING CLASS DEFINITIONS CITS1001

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

6.092: Java for 6.170

Programming for Mobile Computing

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

A A B U n i v e r s i t y

Lec 3. Compilers, Debugging, Hello World, and Variables

CSC Java Programming, Fall Java Data Types and Control Constructs

Today s Agenda. Quick Review

Exam 1 - (20 points)

Java Identifiers, Data Types & Variables

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

PROGRAMMING FUNDAMENTALS

Introduction to Java Programming

JAVA MOCK TEST JAVA MOCK TEST II

Programming II (CS300)

OBJECT INTERACTION. CITS1001 week 3

Computer Science II Data Structures

Homework Set 2- Class Design

Understanding class definitions. Looking inside classes (based on lecture slides by Barnes and Kölling)

Basic Operations jgrasp debugger Writing Programs & Checkstyle

VARIABLES AND TYPES CITS1001

CITS1001 week 4 Grouping objects

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Second-generation: Assembly language. Figure 6.1 Generations of programming languages. Assembly Language Characteristics.

Chapter 6: Programming Languages

Chapter3: Introduction to Classes and Objects

Scope of this lecture

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

Structured Programming

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

OBJECTS FIRST WITH JAVA 5TH EDITION PDF

Objects and Classes Lecture 2

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

2. The object-oriented paradigm

Values, Variables, Types & Arithmetic Expressions. Agenda

CE221 Programming in C++ Part 1 Introduction

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

JAVA GUI PROGRAMMING REVISION TOUR III

Java Basic Datatypees

9 Working with the Java Class Library

AP Computer Science A Summer Assignment

Some miscellaneous concepts

Defining Classes. Chap 1 introduced many concepts informally, in this chapter we will be more formal in defining

Objects First With Java 5th Edition Solutions

Java. Representing Data. Representing data. Primitive data types

Lecture 6 Introduction to Objects and Classes

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 4

C# INTRODUCTION. Object. Car. data. red. moves. action C# PROGRAMMERS GUIDE LESSON 1. CsGuideL1.doc. Date Started: May 8,2001

SELECTION. (Chapter 2)

Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A

Sri Vidya College of Engineering & Technology

Chapter 11: Create Your Own Objects

JAVA PROGRAMMERS GUIDE LESSON

Grouping objects. Main concepts to be covered

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

EXAM Computer Science 1 Part 1

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types

OBJECT INTERACTION CITS1001

A SHIFT OF ACCENT IN INTRODUCTORY OBJECT ORIENTED PROGRAMMING COURSES. Eugeni Gentchev*, Claudia Roda**

DATA STRUCTURES CHAPTER 1

COMP Primitive and Class Types. Yi Hong May 14, 2015

OOSE2 Vererbung und Polymorphie mit BlueJ

Guessing Game with Objects

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Lecture 1: Overview & Intro to Java

CS 170, Section /3/2009 CS170, Section 000, Fall

Software Practice 1 Basic Grammar

Test 1. CSC 121 Lecture Lecturer: Howard Rosenthal. March 4, 2014

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

The class diagram contains only 2 elements: LabClass and Student. The LabClass class is linked to the Student class.

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Software Practice 1 - OOP (1) Class and Method

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

CSI33 Data Structures

CS212:Data Structure

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

CS313D: ADVANCED PROGRAMMING LANGUAGE

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Curriculum Map Grade(s): Subject: AP Computer Science

Software Practice 1 - OOP (1) Class and Method What is OOP? Defining Classes Using Classes References vs. Values Encapsulate

Introduction to CS102

Express Yourself. Writing Your Own Classes

Introduc)on to tes)ng with JUnit. Workshop 3

Fundamentals of Programming Data Types & Methods

Transcription:

Object Oriented Design: Identifying Objects

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?

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 Classes Behaviors/actions Information/data Input/output

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

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

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

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

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 Copyright 2012 Pearson Education, Inc.

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. visibility modifier type variable name private int size; Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, 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 Storage Min Value Max Value byte short int long 8 bits 16 bits 32 bits 64 bits -128-32,768-2,147,483,648 < -9 x 10 18 127 32,767 2,147,483,647 > 9 x 10 18 float double 32 bits 64 bits +/- 3.4 x 10 38 with 7 significant digits +/- 1.7 x 10 308 with 15 significant digits Copyright 2012 Pearson Education, Inc.

Constructors public Square() { x = 0; y = 0; size = 0; color = 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. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling

Methods method header/signature visibility modifier return type method name /** * Gets the size of the square. */ public int getsize() { return size; } start and end of method body (block) parameter list (empty) return statement Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, 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 and submit Lab 2 Work with Codingbat exercises Read Chapter 2