Download presentation
Presentation is loading. Please wait.
Published byShavonne Watson Modified over 8 years ago
1
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 for each successive module 6. Desk-check each module in top-down fashion
2
design.ppt2 advantages of structured programs: can be easily updated and maintained can easily be changed division into tasks makes them easy to understand easy to construct can test modules individually easy to test and debug - easier to isolate errors
3
design.ppt3 Structured Design focuses on control structures Works best for problems with complex control flow and simple data types Programming in the small Top-level modification may affect low-level algorithms Less prone to code reuse
4
design.ppt4 Program Development Structured or Top-Down Design –Data is secondary Object-oriented design(OOD) –Basis: information hiding (encapsulation) –Views software system: Set of interacting objects each object has its own private state
5
design.ppt5 Object-Oriented Design Focus on entities(objects) and operations –object - self-contained entities composed of data and operations on that data identify major objects in the program, with associated operations (algorithms) data plays major role Modular - break into objects –Short, simple modules
6
design.ppt6 OOD, OOP Works best for problems with many entities or algorithms with complex data structures, arge programs, many objects Encapsulation – data is enclosed, control flow is encapsulated inheritance - adapt an existing class Reuse Maintenance Works with structured design
7
design.ppt7 OOP C++ Smalltalk Eiffel Java
8
design.ppt8 OOD & Structured Design Start with OOD for better modularity If data structures not obvious, try structured approach – i.e.mathematical In each level of top-down design, define objects Use off-the-shelf objects
9
design.ppt9 Characteristics of OOD Objects are abstractions of real-world and system entities Object independence Object representations are hidden System functionality is given by object operations
10
design.ppt10 Object Container for a set of data and the operations that need to be performed on it properties –name –data in the form of a set of attributes –set of operations or methods that can be performed on the data –it is an instance of a class
11
design.ppt11 Example objects Car: –Name – license plate –Attributes – make, model, color, etc. –Methods – accelerate, brake, etc. Payroll problem - employee –Name – emp1 –Attributes – empNumber, payRate, hrsWorked –Methods – CalcPay
12
design.ppt12 Methods –Manipulate values stored in an object's attributes –Can only act on data inside the object Instantiation –Creating objects from classes Constructor –Special methof called when the object is created
13
design.ppt13 Steps in creating an OO solution Identify the objects and the methods to be performed Determine the relationship between the objects Design the algorithm for the methods, using structured design Develop the mainline algorithm
14
design.ppt14 Step 1:Identify the objects and operations Object –Instance of a class –Variable of a built-in type Operation –Any action that manipulates data Approaches –Grammatical – nouns and verbs –Identify tangible entities
15
design.ppt15 Step 2: Organize Objects and Operations Subobject – object contained within another object –Has-a relationship Attach operations to objects –If the object is class instance -> member function someObject.DoSomething(); –If object is built-in type -> use built-in operator someInt++ –Or global function DoSomething(someInt); If operation cannot be linked to one object – use global function
16
design.ppt16 Abstract Data Types Abstraction - separating the qualities of an object from the details of how it works what, rather than how control abstraction - separate logical properties of an action from its implementation,exa. Function data abstraction - separate data type's logical properties from its implementation
17
design.ppt17 example ADT Type –IntList Domain –collection of up to 100 integer values –1. Choose data types that already exist integer array, int value for length Operations –Insert, Delete, Search, Sort, Print –2. Implement each operation algorithms
18
design.ppt18 Example: Type TimeType Domain each TimeType value is a tod in the form of hours, minutes, seconds Operations Set the time Print the time Increment the time by one second Compare two times for equality Determine if one time is < another
19
design.ppt19 class TimeType { public://can be accessed by client void Set( int h, int m, int s);//member functions void Increment(); void Write() const; Boolean Equal (TimeType) const; Boolean LessThan (TimeType) const; TimeType(); TimeType(int h,int m, int s); private://can be accessed by member functions int hrs;//member variables int mins; int secs; }; creates a data type note convention of declaring public first for visibility
20
design.ppt20 Class Objects or Class Instances TimeType startTime; TimeType endTime; Reference member with Classvar.member startTime.Increment(); startTime.Set(5,20,0); endTime.Set(inputHrs, inputMins, inputSecs); endTime.write(); if (startTime.LessThan(endTime))...
21
design.ppt21 Classes only one copy of each member function class object vs class member like a built-in type: –can declare multiple objects of a class –can pass class objects as parameters, can return as function value –can be automatic or static Not like a built-in type: –cannot use built-in ops such as +, ==
22
design.ppt22 Objects Object – self contained entity encapsulating data and operations on the data –Instance of an ADT –Instance variable – private data member An object has an internal state –State – current value of its private data –Methods – public member function Only means by which an object can be inspected or modified –Message passing (call to member function)
23
design.ppt23 Class relationships 1.Two classes are independent of each other and have nothing in common. 2.Two classes are related by inheritance. One class acquires the properities of another Base class derived class – inherits all properties of base 3.Two classes are related by composition. The internal data of one class includes an object of another class
24
design.ppt24 Isa –Inheritance- receives all attributes and methods of its parent Hasa –Class contains instance of another class Polymorphism –Method overriding – parent class provides a mthod, inheriting child class defines its own version –Method overloading – methods have the same name
25
design.ppt25 Inheritance between classes allows us to create an object derived from another one, so that it may include some of the other's members plus its own ones. For example, series of classes that describe polygons like our CRectangle, or like CTriangle. –Cpolygon common features, like for example, the one that both can be described by means of only two sides: height and base. –derive the two referred ones, CRectangle and CTriangle.
26
design.ppt26 The class CPolygon would contain members that are common for all polygons. In our case: width and height. And CRectangle and CTriangle would be its derived classes This
27
design.ppt27 Classes derived from others inherit all the visible members of the base class. –That means that if a base class includes a member A and we derive it to another class with another member called B, the derived class will contain both A and B. class derived_class_name: public base_class_name; –public may be replaced by any of the other access specifiers protected or private, and describes the access for the inherited members,
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.