 Write a description (or use one provided)  Create an initial encapsulation  Refine the encapsulation  Identify helpful constructors  Think about.

Slides:



Advertisements
Similar presentations
Written by: Dr. JJ Shepherd
Advertisements

CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Classes, Encapsulation, Methods and Constructors Class definitions Scope of Data –Instance data –Local data The this Reference Encapsulation and Java.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Object Oriented Programming Philosophy. Part 1 -- Basic Understanding & Encapsulation.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
CSE 1302 Lecture 7 Object Oriented Programming Review Richard Gesick.
Chapter 8 Friends and Overloaded Operators. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Friend Function (8.1) Overloading.
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Creating Classes and Objects Chapter Microsoft Visual Basic.NET: Reloaded 1.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
10-Nov-15 Java Object Oriented Programming What is it?
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Chapter 3 (B) 3.5 – 3.7.  Variables declared in a function definition’s body are known as local variables and can be used only from the line of their.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
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.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
Constructor It is a special member of a class that has the following characteristic 1)It has the same name as of its class. 2)It don’t have an explicit.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
1 Chapter 9 Introduction to Classes and Objects Program Development and Design Using C++, Third Edition.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
Constructors and Destructors
Written by: Dr. JJ Shepherd
More About Objects and Methods
Programming with ANSI C ++
Topic 7 Introduction to Classes and Objects
Agenda Warmup AP Exam Review: Litvin A2
More About Objects and Methods
About the Presentations
Inheritance Often, software encapsulates multiple concepts for which some attributes/behaviors overlap E.g. A computer (role-playing) game has: Monsters:
Corresponds with Chapter 7
Constructors and Destructors
JAVA CLASSES.
CMSC202 Computer Science II for Majors Lecture 07 – Classes and Objects (Continued) Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
Designing a class.
Creating and Using Classes
Introduction to Computer Science and Object-Oriented Programming
Chapter 4 Test Review First day
Presentation transcript:

 Write a description (or use one provided)  Create an initial encapsulation  Refine the encapsulation  Identify helpful constructors  Think about the need for private methods  Identify helpful overloaded methods  Identify helpful overloaded constructors  Identify class attributes  Identify class behaviors

 Should include what we know about the object data  Should include what the object should be able to do

 Identify nouns and verb phrases in the description.  Nouns are data. What data types?  Verbs are the methods. What parameters do they need? What do they need to return?

 The money class will represent US Money amounts. Once created a particular Money object cannot change.  We need to be able to add two Money objects to get a third, subtract two Money objects, multiply a money object by a value (such as.05) to get a new Money amount and divide a Money object by a value (such as 2.5).  We must also be able to compare Money objects to determine which is larger, small or if they are the same.  We must be able to display a Money object as normal dollars and cents.  Money may only be a whole number of cents. In other words, Money object may be 3 dollars and 12 cents, but not 3 dollars and 12.5 cents.

 On your whiteboards, begin writing the class. You should carefully think about the instance variables that you need. How will you internally store money values?  What methods are directly suggested by the description? (Don’t worry about constructors at this point).

 Do the attributes really reflect the state of the object? Are there any that are better served in the bodies of the methods themselves.  Are there any methods that may be able to be used in different ways? Or can we use one method as a helper method to another.

 How will we want to build new Money objects?  What makes sense for the user of this class to do?

 These can be methods that would be “utility” methods to users of the class or could be a helper method for other methods in the class.  Private if only used inside of the class; public if a utility.

 Different parameter types may have subtle differences.  We may want to provide different interfaces if, for example, we have a similar function but want to pass in different parameters.  Or, if we want to allow the possibility of different numbers of parameters (min method).

 May obviate the need to have overloaded methods in the case of cardinality (handle 2, handle 3, handle more).  See VarargsDemo1.javaVarargsDemo1.java

 Should we have a default constructor? ◦ Not automatic if any other constructor is defined  Should we have multiple explicit value constructors? ◦ Are there multiple ways of initializing data  Are there methods that can help the constructor do it’s job? ◦ Adjust methods to check for validity  Constructors can call other constructors. ◦ Stock.java Stock.java ◦ CopyConDemo.java CopyConDemo.java

 Helpful constants, special values  Common values used across all objects  Object counters  What might we want to include that are “constant” money amounts?

 Utilities ◦ Math class  Type conversion ◦ Integer.parseInt()  “Factory” methods (produce an object of the specified type) ◦ example is NumberFormat.getCurrencyInstance()  returns a NumberFormat object that is formatted for currency – we don’t have to specify the format