Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.

Slides:



Advertisements
Similar presentations
Lab 8 Ordered list. OVERVIEW In an ordered list the elements are maintained in ascending (or descending) order based on the data contained in the list.
Advertisements

Overview of Data Structures and Algorithms
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Software Engineering and Design Principles Chapter 1.
Copyright W. Howden1 Lecture 13: Programming by Contract.
Software Testing and Quality Assurance
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
COS Sept 9, 2005 Key Issues in Programming Stefan Brandle.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Computer Science 1620 Programming & Problem Solving.
Information Hiding and Encapsulation
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Chapter 1 Principles of Programming and Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Modules, Hierarchy Charts, and Documentation
Chapter 10 Classes Continued
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
C++ fundamentals.
Computer Science 340 Software Design & Testing Design By Contract.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
1 Life Cycle of Software Specification Design –Risk Analysis –Verification Coding Testing –Refining –Production Maintenance.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Object Oriented Software Development
The Software Development Process
Pre- and postconditions, Using assertions and exceptions 1 Pre- and postconditions Using assertions and exceptions.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Flow of Control and Program Style n Nested if statements n C++ struct n Program Style n Lab Exercise.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Object Oriented Programming
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
Class Design I Class Contracts Readings: 2 nd Ed: Section 9.5, Advanced Topic nd Ed: Section 8.5, Advanced Topic 8.2 Some ideas come from: “Practical.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
Loop Invariants and Binary Search Chapter 4.4, 5.1.
Chapter 2 Principles of Programming and Software Engineering.
Principles of Programming. Achieving an Object-Oriented Design  Abstraction and Information Hiding  Object-Oriented Design  Functional Decomposition.
Principles of Programming & Software Engineering
Design by Contract Jim Fawcett CSE784 – Software Studio
Principles of Programming and Software Engineering
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
Figure 1.1 The life cycle of software as a water wheel that can rotate from one phase to any of phase.
Figure 1.1 The life cycle of software as a water wheel that can rotate from one phase to any of phase.
Slides by Steve Armstrong LeTourneau University Longview, TX
Chapter One: An Introduction to Programming and Visual Basic
Defining Classes and Methods
Chapter 2. Problem Solving and Software Engineering
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Presentation transcript:

Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three principles of Object Oriented Design Encapsulation – discussed earlier Inheritance – discussed later in the course Polymorphism – discussed later in the course

Object Design – Identify Objects Identify objects Identify objects that exist in the problem statement and requirements Typically, select nouns, ignoring irrelevant ones, such as synonyms Look for relationships amongst the (real-world) objects that were identified Generalization – relates to inheritance Containment – where one object contains another Multiplicity – determine the quantity relationships between objects (e.g. one bank can have many accounts)

Object Design – Identify Operations Identify the operations of objects Typically, select verbs, ignoring irrelevant ones, such as actions performed by the user Associate each operation with the object that is responsible for providing the behaviour Note that an object should be responsible for modifying its own data

Object Design – Create Interface An interface should be created for each object that is to be represented by a class (rather than a variable) The interface describes how the class can be used, by specifying its public operations There are a number of ways of creating interfaces, e.g. C++ Header files Java Interface An interface should include: Class invariants (conditions that must be true for an object) Public methods, for each such define: Parameter lists Return type Purpose (i.e. a description) Pre and post conditions

Class Invariants A class invariant is an invariant on the values of the variables of an object, For example: Account balance is always >= 0 Account ID numbers are unique and cannot be modified All object constructors and mutators should respect class invariants That is, they should always make sure that class invariants are true

Pre-Conditions A pre-condition is an assertion about conditions at the beginning of a method An assertion is a statement about a condition It is part of the "contract" implicit in a method If the pre-conditions are not true then the method is not guaranteed to produce the desired results e.g. for binary search, there is a pre-condition that the array or list being searched is sorted, it is not, there is not guarantee that the correct result will be returned Or, to put it another way, that the post-conditions will hold

Post-Conditions A post-condition is an assertion about conditions at the end of a method The post-conditions describe the state after the method has been run They therefore describe the desired output of a method To prove that an algorithm is correct we need to prove that, if the pre-conditions are correct, following the steps of the algorithm will lead to the post- conditions We should be able to show how the each step of an algorithm leads to the post-conditions

Example (Object Oriented Design) You have been hired to design an application for a company to record information about its employees. You have been given the following information about the application's requirements. The company has a number of branches. It is necessary to record the address of the building occupied by each branch, as well as the manager (who is an employee). The company also needs to record the unique employee ID, first name, last name and annual salary of each employee. Each employee works for one and only one branch. The application will be used to perform the following tasks: Insert and delete (fire) employees, and transfer them between branches Change any employee information (with exception of the which employee's IDs cannot be changed, also note that an employee's salary cannot go below zero) Retrieve employee information Insert and delete branches; branches can only be deleted if they have no employees Change branch data Retrieve branch data, including the monthly payroll costs (the sum of the annual salaries of all employees who work for the branch divided by 12)

Object Interaction Design Design the entire application by describing how the objects are to interact with each other One approach is to write a high level algorithm and then decompose it into several methods Each such method should have one specific purpose

Operation Design Each of the operations identified in the object design should be designed If possible, re-use previously written methods or functions Otherwise design algorithms to implement each operation

Test Design Determine how each class (or unit, or module) will be tested before writing the application Write unit test cases that test the entire range of input that can be given to a method Expected values Boundary values Invalid values For each input specify the expected result and when testing is performed compare this to the actual result Debug where necessary!

What makes a good program? Modularity Favorable impact on program development Modifiability Use of methods and named constants Ease of Use Considerations for the user interface Program should prompt the user for input A program should always echo its input The output should be well labeled and easy to read

What makes a good program? Efficient Fail-Safe Programming Fail-safe program A program that will perform reasonably no matter how anyone uses it Types of errors: Errors in input data Errors in the program logic

What makes a good program? Style Five issues of style Extensive use of methods Use of private data fields Error handling Readability Documentation