Introduction to Object Oriented Design Lecture 11.

Slides:



Advertisements
Similar presentations
Python Objects and Classes
Advertisements

Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Object-Oriented PHP (1)
Road Map Introduction to object oriented programming. Classes
Understanding class definitions Looking inside classes 3.0.
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.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 15 – Digital Clock Application: Building Your.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
ASP.NET Programming with C# and SQL Server First Edition
Pseudocode.
Pseudocode.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
DCT 1123 Problem Solving & Algorithms
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Chapter 4 Objects and Classes.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Object Oriented Programming Philosophy. Part 1 -- Basic Understanding & Encapsulation.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
1 Object-oriented design requires that we interact with a problem in much the same way that we interact with our world – we treat it as a set of separate.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
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.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved More about.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
© 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:
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
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 19: Introduction to Classes Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Chapter 11 An introduction to object-oriented design.
Introduction To Objects Oriented Programming Instructor: Mohammed Faisal.
LO: We’re learning to outline a program using Pseudo Code.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Chapter 11 An introduction to object-oriented design.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved More about.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Object-Oriented Programming: Classes and Objects
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
More about OOP and ADTs Classes
OBJECT ORIENTED CONCEPTS
Object-Oriented Programming: Classes and Objects
Computer Programming.
Encapsulation & Visibility Modifiers
Corresponds with Chapter 7
Programming with Microsoft Visual Basic 2008 Fourth Edition
Object-Oriented Programming
More about OOP and ADTs Classes
Object-Oriented Programming
Object-Oriented Programming
Object-Oriented Programming
Agenda Warmup Lesson 2.6 (Constructors, Encapsulation)
Object-Oriented PHP (1)
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Presentation transcript:

Introduction to Object Oriented Design Lecture 11

Procedural Design Program design so far: Procedural approach  concentrate on what program does, data will be considered when the program need input, output or calculation. Procedural design : involves indentifying and organising the processes in the problem solution Backward: –Limitations in the development of large systems or networked and multi-user systems. (even if they are structured and modular) –If programmer work in a team, the same blocks code are duplicated in different parts of the system.

Object Oriented Design We interact with the problem in the same way that we interact with our world  we treat it as a set of separate objects that perform actions and relate to each other.

Encapsulation and information hiding Object are said encapsulate their data and the process for the data. Internal process and data of the object work independently from the system. In OOD  principle of information hiding  to make object as robust and independent as possible.

Objects A container for a set of data and the operations that need to be performed on it. An object has properties: –Identity –Attributes –Methods or operations Example: car  identity: licence plate, attributes: model, number of doors, body lenght, colour, speed, etc. Operation: accelerate, stop, brake, run, etc.

Classes and Objects Class: pattern of an object, which define: the basic relations, attributes, operations available to the object of the class. The process of creating objects from classes is called: instantiation Object is called an instant of its class. Example: class: Flower, instant: rose, orchid, jasmine, etc

A car class Car Factory Model Doors Bodylength Colour Speed Accelerate() Stop() Brake() Turn(direction)

Car objects RVJ635:Car Factory = `Toyota` Model = `Inova` Doors = 5 Bodylength = 300 Colour = ´Black` Speed = 80 Accelerate() Stop() Brake() Turn(direction) SVU478:Car Factory = `Ford` Model = `Falcon` Doors = 4 Bodylength = 200 Colour = ´red` Speed = 60 Accelerate() Stop() Brake() Turn(direction)

Attributes : Properties or characteristics of particular object. Object of the same class will have the same attributes.

Constructors The process of instantiating an object from the class is performed when constructor is called. Constructor assign initial values to the new object‘s attributes Constructor usually have the same name as their class Pseudocode: Create object-name as new Class-name()

Accessors and mutators The value in the attributes hidden from external objects. For safety, only special public operations, known as accessors and mutators can acces it. Accessors : pass attribute values to external object  keyword: get, example: getName() Mutators: enable external object to change the value in attributes  keyword: set, example: setPayRate()

Visibility Public : operate services required by other object Private : operate services required by internal actions in an object and cannot be accessed directly from outside of the object.

Steps in creating an object oriented solution 1.Identify the classes, together with their attributes, responsibilities and operations 2.Determine the relationship between the object of those classes 3.Design the algorithms for the operations, using structured design 4.Develop a test or driver algorithm

Example 11.1 Print student results Design a class to manage student results in a subject. A unique student number identifies each student. During the course of the subject, each student completes three assignments (representing 40% of the final mark but each scored out of 100) and an examination(also scored out of 100). The final mark is calculated by multiplying the sum of assignments by and the examination by 0.6 and adding the two products together. The class will allow a user to update an assignment mark or an examination mark, and to print the final mark along with the student number for each student.

Step 1: Identify the classes, together with their attributes, responsibilities and operations Underline the nouns and nouns phrases to identify the object and their attribute: Design a class to manage student results in a subject. A unique student number identifies each student. During the course of the subject, each student completes three assignments (representing 40% of the final mark but each scored out of 100) and an examination(also scored out of 100). The final mark is calculated by multiplying the sum of assignments by and the examination by 0.6 and adding the two products together. The class will allow a user to update an assignment mark or an examination mark, and to print the final mark along with the student number for each student. We need: student object, with attributes: unique student number, three assignment and an examination. No need to make final mark as attribute because it can be derived from the other attributes.

Underline the verb and verb phrases to identify the responsibilities and the operations that the object needs to perform : Design a class to manage student results in a subject. A unique student number identifies each student. During the course of the subject, each student completes three assignments (representing 40% of the final mark but each scored out of 100) and an examination (also scored out of 100). The final mark is calculated by multiplying the sum of assignments by and the examination by 0.6 and adding the two products together. The class will allow a user to update an assignment mark or an examination mark, and to print the final mark along with the student number for each student. There are three public or visible operations: update an assignment mark or update an examination mark, and to print the final mark and one private operation: calculate final mark

Two mutator will be needed: one to update the assignment, called setAsst(), and another to update the exam mark, called setExam() The input mark must be validated before calculation, so another private operation to validate the mark is required.

Class table ClassAttributesResponsibilitiesOperations StudentstudentNumbe r asstOne asstTwo asstThree examMark Update assignment mark Update exam mark Print final mark Calculate final mark +setAsst(asstNum, result) +setExam(result) +validateMark() +calculateFinalMark() +printFinalMark()

Step 2: Determine the relationship between the object of those classes There is only one object in the solution, so we can move to the next step

Step 3: Design the algorithms for the operations, using structured design Public operations –An algorithm is required for each operation in the object table –The mutator, setAsst() requires two parameters be passed to it: the assignment number and the result of the assignment –The result, passed as parameter, will be validated by the private operation, validateMark(), before updating mark to the assignment

Mutator setAsst() setAsst(asstNum, result) validateMark(result, validInput) IF validInput THEN CASE OF asstNum 1: asstOne = result 2: asstTwo = result 3: asstThree = result OTHERWISE Report invalid assignment number error ENDCASE ENDIF END

Mutator setExam() setExam(result) validateMark(result, validInput) IF validInput THEN examMark = result ENDIF END

printFinalMark() calculateFinalMark(finalMark) Print studentNumber, finalMark END

Private Operation validateMark(result, validInput) Set validInput to true IF (result 100) THEN Set validInput to false Report invalid result error ENDIF END

calculateFinalMark(finalMark) finalMark = (asstOne + asstTwo + asstThree) * finalMark = finalMark + (examMark * 0.6) END

Step 4: Develop a test or driver algorithm Rather than develop a mainline algorithm, we will write a simple Test class, calles testStudent, to triall the Student class. A constructor for Student class, named Student, also needed to create student object and initialise the studentNumber attribute

Constructor Student(inStudentNumber) set studentNumber to inStudentNumber set asstOne to 0 set asstTwo to 0 set asstThree to 0 set examMark to 0 END

The value of studentNumber is passed as a parameter to the constructor, which will create a Student object with pseudocode: Create student as new Student(studentNumber)

Finally, triall the student class: testStudent() Set studentNumber to Create sudent1 as new Student(studentNumber) set asstNum to 2 set result to 80 student1.setAsst(asstNum, result) Set studentNumber to Create sudent2 as new Student(studentNumber) set asstNum to 1 set result to 95 student2.setAsst(asstNum, result) student1.printFinalMark() student2.printFinalMark() END

EXERCISE Write an object oriented design for a program that will prompt for and receive the diameter of a circle, and calculate and display the radius and the area of that circle. –Design the class table –Write an algorithm for each operation –Write an algorithm for a circle Test class.