1 / 14

OBJECT ORIENTED DESIGN

OBJECT ORIENTED DESIGN. CMPS260 ULL Computer Science Department. OBJECT DEFINITION. IDENTIFY THE OBJECTS IN AN APPLICATION SPECIFY THEIR STRUCTURES, VALUES AND OPERATIONS HOOK THEM TOGETHER TO SOLVE THE PROBLEM (SWE). OBJECTS. OBJECTS ARE THE ENTITIES IN THE PROBLEM STATEMENT (NOUNS)

ursa-bright
Download Presentation

OBJECT ORIENTED DESIGN

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OBJECT ORIENTED DESIGN CMPS260 ULL Computer Science Department

  2. OBJECT DEFINITION • IDENTIFY THE OBJECTS IN AN APPLICATION • SPECIFY THEIR STRUCTURES, VALUES AND OPERATIONS • HOOK THEM TOGETHER TO SOLVE THE PROBLEM (SWE)

  3. OBJECTS • OBJECTS ARE THE ENTITIES IN THE PROBLEM STATEMENT (NOUNS) • OBJECTS HAVE STRUCTURES, VALUES AND OPERATIONS • OBJECTS INTERACT WITH OTHER OBJECTS (VISIBILITY) • OBJECTS ARE ABSTRACTIONS

  4. ABSTRACTION • THE REMOVAL OF NON-ESSENTIAL DETAILS • PROVIDES AN INTERFACE FOR THE USER • HIDES THE IMPLEMENTATION FROM THE USER • PROVIDES FOR ENFORCEMENT

  5. CLASSES • ABSTRACT DATA TYPES • SPECIFICATION (INTERFACE) • IMPLEMENTATION • COMPILED SEPARATELY • INTERACT VIA MESSAGE PASSING

  6. DRIVER • PROCEDURAL CONTROL PROGRAM • CREATES OBJECTS • USES OBJECTS • CONTROLS SYSTEM FLOW • THE SMALLER THE BETTER

  7. SUMMARY • OBJECTS ARE THE BASIC COMPONENTS • ABSTRACTIONS ARE DEFINED AND ENFORCED • PROCEDURAL ASPECTS ARE INCLUDED IN THE CLASSES AND THE DRIVER

  8. SAMPLE OBJECTS • PERSON • STUDENT (DERIVED FROM PERSON) • COURSE • CLASS (INSTANCE OF A COURSE) • SCHEDULE (CONTAINS A STUDENT AND THEIR CLASSES)

  9. EXAMPLE ATM MACHINE INTERFACE VERIFY, WITHDRAW … ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ IMPLEMENTATION HIDDEN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENFORCEMENT CRITICAL

  10. ATM OBJECT DIAGRAM IMPLEMENTATION (HIDDEN) (BETTER BE) INTERFACE (PUBLIC) ACCT DATA ??? USERS VERIFYACCT WITHDRAW FUNDS IN & OUT ??? DEPOSIT CHK BAL

  11. ~~~~~~~~~~~~~~~~~~~ SPECIFICATION FILE ~~~~~~~~~~~~~~~~~~~// Declare a class to represent the date ADT// This is file DateType.hclass DateType{public: void Initialize(int newMonth, int newDay, int newYear); int YearIs() const; // returns year; int MonthIs() const; // returns month; int DayIs() const; // returns day; enum RelationType {LESS, EQUAL, GREATER}; RelationType ComparedTo(DateType aDate);private: int year; int month; int day;};

  12. ~~~~~~~~~~~~~~~~~~~ IMPLEMENTATION FILE ~~~~~~~~~~~~~~~~~~~// Define member functions of class DateType.// This is file DateType.cpp.#include "DateType.h" // gain access to the specificationvoid DateType::Initialize(int newMonth, int newDay, int newYear)// Post: year is set to newYear.// month is set to newMonth.// day is set to newDay.{ year = newYear; month = newMonth; day = newDay;}// Accessor funtions for the private data membersint DateType::MonthIs() const// Accessor function for month.{return month;}int DateType::YearIs() const// Accessor function for year.{return year;}int DateType::DayIs() const// Accessor function for day.{return day;}

  13. RelationType DateType::ComparedTo(DateType aDate)// Pre: Self and aDate have been initialized.// Post: Function value = LESS, if self comes before aDate.// = EQUAL, if self is the same as aDate.// = GREATER, if self comes after aDate.{ if (year < aDate.year) return LESS; else if (year > aDate.year) return GREATER; else if (month < aDate.month) return LESS; else if (month > aDate.month) return GREATER; else if (day < aDate.day) return LESS; else if (day > aDate.day) return GREATER; else return EQUAL;}

  14. ~~~~~~~~~~~~~~~~~~~ DRIVER ~~~~~~~~~~~~~~~~~~~#include "DateType.h"#include <iostream>using namespace std;int main(){ DateType today; DateType anotherDay; today.Initialize(8, 24, 2006); anotherDay.Initialize(8, 25, 2006); cout << " Today is " << today.MonthIs() << "/" << today.DayIs() << "/" << today.YearIs() << endl; cout << " Another date is " << anotherDay.MonthIs() << "/" << anotherDay.DayIs() << "/" << anotherDay.YearIs() << endl; switch (today.ComparedTo(anotherDay)) { case LESS : cout << "today comes before anotherDay"; break; case GREATER : cout << "today comes after anotherDay"; break; case EQUAL : cout << "today and anotherDay are the same"; break; } return 0;}

More Related