Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.

Slides:



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

This is Java Jeopardy Writing Methods…chapter 4…
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Classes, Encapsulation, Methods and Constructors Class definitions Scope of Data –Instance data –Local data The this Reference Encapsulation and Java.
C++ Classes in Depth. Topics Designing Your Own Classes Attributes and Behaviors Writing Classes in C++ Creating and Using Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Software Lifecycle A series of steps through which a software product progresses Lifetimes vary from days to months to years Consists of –people –overall.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Ranga Rodrigo. Class is central to object oriented programming.
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 01] Introduction to.
Introduction to Object-oriented programming and software development Lecture 1.
An Object-Oriented Approach to Programming Logic and Design
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
1.  A method describes the internal mechanisms that actually perform its tasks  A class is used to house (among other things) a method ◦ A class that.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Java Classes Using Java Classes Introduction to UML.
Introduction to Object Oriented Design Version 1.1.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
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-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
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.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Unified Modeling Language (UML)
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
A High Flying Overview CS139 – Fall 2010 How far we have come.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Introduction to Classes and Objects
Classes and OOP.
Chapter 3: Using Methods, Classes, and Objects
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
CompSci 230 Software Construction
Chapter 4: Writing Classes
Creating and Using Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 4: Writing classes
Implementing Classes Chapter 3.
Object-Oriented Programming
Defining Classes and Methods
Classes, Objects, Methods and Strings
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
COP 3330 Object-oriented Programming in C++
Object-Oriented Programming
Object Oriented Programming in java
Defining Classes and Methods
2.1 Introduction to Object-Oriented Programming
Presentation transcript:

Introduction to Object Oriented Design

Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams

Objectives At the completion of this topic, students should be able to: Design classes for use in a C# program Explain the difference between a class and an object Explain what attributes and behaviors are Explain the terms encapsulation and data hiding Create accurate class diagrams using UML

Motivation

Consider the following simple program

Press this button to add 1 to the counter

Press this button to subtract 1 from the counter

Press this button to reset the count to zero.

To make the counter work, we have to (1)Declare a variable to hold the value of the counter. This variable must be visible to all methods in the Form.

To make the counter work, we have to (2) In the Form constructor, set this value to zero.

To make the counter work, we have to (3) Write methods for each button, for example

The Problem! The user interface code gets all tangled up with the “business logic” of the program. This makes the code hard to maintain, hard to debug, and makes the code hard to re-use.

To solve this problem, good programmers keep everything in neat, separate piles.

To solve this problem, good programmers keep everything in neat, separate piles. User interface code Business logic

The User Interface code belongs in the Form. It’s main tasks are to display information to the user, and to get input from the user.

We need a way of packaging up the application’s data and the methods that operate on the data in one unit, so that the data is visible to all of the methods that will work on it, but keep it separate from the user interface logic. We can, if we use objects!

Objects

Key Concept An object often models things in the real world A counter

Real world objects have attributes An object’s attributes describe its “state of being” depending upon the application, some attributes are more important than others value size color

Real world objects have attributes An object’s attributes describe its “state of being” For our application, we are interested in value

An object also has behaviors behaviors define how you interact with the object Get the current value of the counter Subtract one from The counter Add one to the counter Reset the counter To zero

An Object’s Attributes and Behaviors Should Work Together this is called cohesion

An Object’s Attributes and Behaviors Should Work Together This object has strong cohesion, because all of the operations work on the single data value in the counter, it’s value.

A Class is a blueprint that a program uses when it creates an object. A class reserves no space in memory When an object is created from the class blueprint, memory is reserved to hold the object’s attributes. An object is known as an instance of the class. Each object has it’s own space for data.

A class is said to be an abstraction of the real world object that we are modeling.

Encapsulation Counter object Add( ) theValue calling method we should not allow code outside of the object to reach in and change the data directly. Instead, we call methods in the object to do it for us. member data is declared as private member methods are declared as public public and private are called access modifiers

We use a UML Class Diagram to document the data and methods contained in our class.

Counter A UML class diagram is used to describe a class in a very precise way. A class diagram is a rectangle. At the top of the rectangle is the class name. A line separates the class name from the rest of the diagram. class Counter { } Code represented by the UML diagram

Counter - counterValue: int Following the class name we write the data members of the class. A line separates the data members from the rest of the diagram. access modifier: + public - private data member name data type class BowlingTeam { private int counterValue; } Code represented by the UML diagram

+ Add( ): void Following the data members, we write the member methods. access modifier + public - private method name parameters return type class Counter { private int counterValue; public void Add( ){ } } Code represented by the UML diagram Counter -counterValue: int

+ Add( ): void + Subtract: void + Reset( ): void + GetValue( ): int Following the data members, we write the member methods. class Counter { private int counterValue; public void Add( ){ } public void Subtract( ) { } public void Reset( ) { } public int GetValue( ) { } } Code represented by the UML diagram Counter -counterValue: int

It is important that class diagrams be drawn precisely and that they conform to the form shown in these examples. When you submit a class diagram, the preferred file format is pdf.

The Form object now (1)Creates a Counter object (2)Initializes it (3)Sends messages to the object Counter

The ability to create good models of the real world objects in our programs takes a lot of practice and a long time to develop.

Practice

Design a class that represents “Integer” objects. What are the data members of the class?

Design a class that represents “Integer” objects. Suppose we want methods to set the integer value in the object retrieve the integer value in the object retrieve the reciprocal of the value in the object

Create the UML class diagram Integer

Design a class that represents “StudentInfo” objects. You could use an object of this class to hold the student information you print out at the beginning of each of your programming projects. What are the data members of the class?

Design a class that represents “StudentInfo” objects. Suppose we want methods to set the name, course, and section values in the object retrieve the name, course and section values from the object output the data in the student object

Create the UML class diagram StudentInfo

Design a class that represents a car. The important attributes of a car for this application are how much gas it has in its tank, and what kind of mileage (mpg) it gets. We need member methods (behaviors) that provide the following: - Create a Car object with a given mpg rating - add n gallons of gas to the tank - drive the car y miles - report on how much gas is in the tank

Car

Design a class that represents a student. The important properties of a student for this application are the student’s name, and the scores for two quizzes (10 pts possible on each) and two exams (100 pts possible on each). We need member methods that Create a student object – set all scores to zero Save the score for quiz 1 Save the score for quiz 2 Save the score for exam 1 Save the score for exam 2 Calculates the student’s percent of points possible

Create the UML class diagram Student

Checking Account

Create the UML class diagram Checking Account

PayCheck

Create the UML class diagram Paycheck

A Coin Purse

Create the UML class diagram CoinPurse