Introduction to Object Oriented Design Version 1.1.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

This is Java Jeopardy Writing Methods…chapter 4…
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed.
Visual Basic: An Object Oriented Approach 2 – Designing Software Systems.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Road Map Introduction to object oriented programming. Classes
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
 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.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Chapter 9: Classes with Instance Variables or Classes=Methods+Variables Asserting Java © Rick Mercer.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
State,identity and behavior of objects Sem III K.I.R.A.S.
COMP Classes Yi Hong May 22, Announcement  Lab 2 & 3 due today.
Object Oriented Software Development
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
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.
Classes and Objects. Topics The Class Definition Declaring Instance Member Variables Writing Instance Member Methods Creating Objects Sending Messages.
Java Classes Using Java Classes Introduction to UML.
Object-Oriented Analysis and Design An Introduction.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
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.
Objective You will be able to define and identify the basic components of a java program by taking notes, seeing examples, and completing a lab. Construction.
Object-Oriented Paradigm and UML1 Introduction to the Object- Oriented Paradigm.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Introducing Objects and stuff GABY and MATT Definition: Object: “a class that is the root of the hierarchy tree for all classes in JAVA.” –An object.
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Lecture 08. Since all Java program activity occurs within a class, we have been using classes since the start of this lecture series. A class is a template.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Unified Modeling Language (UML)
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Classes and Objects.
Programming Logic and Design Seventh Edition
Introduction to Classes and Objects
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
The Object-Oriented Thought Process Chapter 1
Chapter 3: Using Methods, Classes, and Objects
Object Oriented Concepts -I
Anatomy of a Class & Method
Introduction to Objects
Introduction to Object-oriented Program Design
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 4: Writing classes
Defining Classes and Methods
Classes, Objects, Methods and Strings
COP 3330 Object-oriented Programming in C++
Defining Classes and Methods
Introduction to Object-Oriented Programming
Defining Classes and Methods
Review of Previous Lesson
2.1 Introduction to Object-Oriented Programming
Introduction to Objects
Presentation transcript:

Introduction to Object Oriented Design Version 1.1

Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams Sequence 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 Create a sequence diagram

Motivation

We have worked on a couple of Bowling Team Programs.

In these program we had a lot of data associated With a bowling team … * bowling scores * names of bowlers * number of people on the team And operations that we wanted to perform on the data * read scores from a file * sort the scores in order * find the average score * output the scores

We have worked on a couple of Bowling Team Programs. If you wrote any methods to do these operations, you probably found yourself passing lots of data around as parameters to the methods.

Wouldn’t it be nice if we could keep the data for a bowling team all in one place, and make the methods that work on the data easier to write? We can, if we use objects!

Objects

Key Concept An object often models things in the real world Bowling Team

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 occupation Average height Shirt color

Real world objects have attributes For our application, we are interested in Number of team members Their bowling scores The bowlers names

An object also has behaviors behaviors define how you interact with the object Find the highest/lowest/average score Record their names Record their scores Sort the scores

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

An Object’s Attributes and Behaviors Should Work Together Cohesion means that methods and data work together, for example, read bowling scores from a file.

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 Bowling Team object readFile( ) names scores 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.

Bowling Team 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 BowlingTeam { } Code represented by the UML diagram

BowlingTeam - numberOfBowlers: 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 numberOfBowlers; } Code represented by the UML diagram

Following the class name we write the data members of the class. A line separates the data members from the rest of the diagram. class BowlingTeam { private int numberOfBowlers; private int[ ] scores; private string[ ] names; } Code represented by the UML diagram BowlingTeam -numberOfBowlers: int - scores: int[ ] - names: string[ ]

+ ReadScores( ): void Following the data members, we write the member methods. access modifier + public - private method name parameters return type class BowlingTeam { private int numberOfBowlers; private int[ ] scores; private string[ ] names; public void ReadScores( ){ } } Code represented by the UML diagram BowlingTeam -numberOfBowlers: int - scores: int[ ] - names: string[ ]

Following the data members, we write the member methods. class BowlingTeam { private int numberOfBowlers; private int[ ] scores; private string[ ] names; public BowlingTeam(){ } public void ReadScores(){ } public void SortScores(){ } public void DisplayScores( ){ } } Code represented by the UML diagram + ReadScores( ): void + SortScores( ): void + DisplayScores( ): void BowlingTeam -numberOfBowlers: int - scores: int[ ] - names: string[ ]

It is important that class diagrams be drawn precisely and that they conform to the form shown in these examples.

Class diagrams are static. They describe how a class looks. To show how objects interact with one another as a program executes, we use a Sequence Diagram.

Consider an Application that contains Book objects And Order objects. They might interact as shown:

anOrder aBook getTitle getPrice calcSalesTax

anOrder aBook getTitle getPrice calcSalesTax The boxes along the top are objects

anOrder aBook getTitle getPrice calcSalesTax These lines represent messages being sent from one object to another

anOrder aBook getTitle getPrice calcSalesTax These lines represent responses (return values)

anOrder aBook getTitle getPrice calcSalesTax This is a message that the object sends to itself

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