480 likes | 623 Views
Introduction to the Object-Oriented Paradigm. Objectives. To explain the essential difference between the procedural and object-oriented (OO) paradigms To summarize the advantages and disadvantages of the OO paradigm
E N D
Introduction to the Object-Oriented Paradigm Object-Oriented Paradigm and UML
Objectives • To explain the essential difference between the procedural and object-oriented (OO) paradigms • To summarize the advantages and disadvantages of the OO paradigm • To explain the basics concepts of the OO paradigm: objects, classes, attributes, and operations Object-Oriented Paradigm and UML
The Procedural Paradigm • Operations are separate from data but manipulate it. • Example: A stack data type • Data store (array, linked list) • Separate operations for pushing, popping, etc. Object-Oriented Paradigm and UML
The Object-Oriented Paradigm • Data is packaged (encapsulated) with the operations that manipulate it. • Example: a stack object • Data store within a stack object • Operations within the stack object Object-Oriented Paradigm and UML
Encapsulation Advantages 1 • Problem and solutionsimilarity—Software objects are like real-world things. • Abstraction—Data structures and algorithm details are ignored in design. • Informationhiding—Implementations can be truly hidden. (Shielding the internal details of a program unit’s processing from other program units) Object-Oriented Paradigm and UML
Encapsulation Advantages 2 • Coupling—Operations are not related through shared data structures. (The degree of connection between pairs of modules) • Cohesion—It’s easier to keep related operations and data together. (The degree to which a module’s parts are related to one another) Object-Oriented Paradigm and UML
Encapsulation Advantages 3 • Reusability—It’s easier to reuse objects than collections of operations and various data structures. • Scalability—Objects can be of arbitrary size. • Newfeatures—The object-oriented paradigm offers new and powerful ways of doing things, as we will see. Object-Oriented Paradigm and UML
Problems with the OO Paradigm • It’s a lot more complicated than the procedural paradigm. • Harder to learn • Harder to use properly Object-Oriented Paradigm and UML
Objects An object is an entity that has properties and exhibits behavior. • Things are encapsulated when they are packaged together in a container. • Objects encapsulate properties and behavior. • Ideally, objects model things in the world. • Example: Traffic simulation Object-Oriented Paradigm and UML
Attributes and Operations An attribute is a named data value held by an object or a class. An operation is a named object or class behavior. A feature is an attribute or operation. Object-Oriented Paradigm and UML
Attribute and Operation Examples Object-Oriented Paradigm and UML
Object Characteristics • Every object has its own attributes and operations, though these may be the same as some other objects. • Every object has a unique identity. • Two objects with the same attributes holding the same values and behaviors are distinct. Object-Oriented Paradigm and UML
Messages • Objects communicate by sending one another messages. • Messages are abstractions of function calls, signals, exceptions, etc. • Ideally, objects send messages that model real-world communications between things. • Example: Traffic simulation Object-Oriented Paradigm and UML
Classes An class is an abstraction of a set of objects with common attributes and operations. • Classes have attributes and operations. • A class is not a set of objects—it is more like a blueprint or a specification. • Objects are said to be instances of classes. Object-Oriented Paradigm and UML
Examples of Classes Object-Oriented Paradigm and UML
Classes and Abstract Data Types • ADT: a set of values (the carrier set) and a collection of operations to manipulate them • A class forms a type but not an ADT • Mathematical entities that can be implemented procedurally or using the OO paradigm • OO techniques provide an excellent way to implement ADTs Object-Oriented Paradigm and UML
UML Class and Object Diagrams Object-Oriented Paradigm and UML
UML • Unified Modeling Language • Developed by Grady Booch, Ivar Jacobson, and James Rumbaugh (the three amigos) at Rational Software Corporation (1994) • Goal to produce a standard OO analysis and design notation • Now a standard controlled by the Object Management Group (OMG) Object-Oriented Paradigm and UML
UML Names • A name in UML is character string that identifies a model element. • Simple name: sequence of letters, digits, or punctuation characters • Composite name: sequence of simple names separated by the double colon (::) • Examples • Java::util::Vector • veryLongNameWithoutPunctuationCharacters • short_name Object-Oriented Paradigm and UML
UML Class Symbol Object-Oriented Paradigm and UML
Attribute Specification Format name : type [ multiplicity ] = initial-value • name—simple name, cannot be suppressed • type—any string, may be suppressed with the : • multiplicity—number of values stored in attribute • list of ranges of the form n..k, such that n <=k • k may be * • n..n is the same as n • 0..* is the same as * • 1 by default • if suppressed, square brackets are omitted • initial-value—any string, may be suppressed along with the = Object-Oriented Paradigm and UML
Examples • weight • weight : real = 40.0 • signal[*] : real = { 0.0 } • charge[3,5,7..10] • hour = 12 Object-Oriented Paradigm and UML
Operation Specification Format name( parameter-list ) : return-type-list • name—simple name, cannot be suppressed • parameter-list • direction param-name : param-type = default-value • direction—in, out, inout, return; in when suppressed • param-name—simple name; cannot be suppressed • param-type—any string; cannot be suppressed • default-value—any string; if suppressed, so is = • return-type-list—any comma-separated list of strings; if omitted (with :) indicates no return value • The parameter-list and return-type-list may be suppressed together. Object-Oriented Paradigm and UML
Examples • rotate() • rotate( degrees : real ) • rotate( in degrees : real = 0.0 ) : Boolean • rotate( inout degrees : real ) • print( s : String[*] ) : void • split( s : String ) : int, String[*] Object-Oriented Paradigm and UML
Attribute and Operation Examples Object-Oriented Paradigm and UML
Class Diagram Uses • Central static modeling tool in object-oriented design • Can be used throughout both the product and engineering design processes Object-Oriented Paradigm and UML
Object Diagrams • Object diagrams are used much less often than class diagrams. • Object symbols have only two compartments: • Object name • Attributes (may be suppressed) Object-Oriented Paradigm and UML
Object Name Format • object-name : class-name[ stateList ] • object-name—simple name • class-name—a name (simple or composite) • stateList—list of strings; if suppressed, the square brackets are omitted • The object-name and class-name may both be suppressed, but not simultaneously. Object-Oriented Paradigm and UML
Object Attribute Format attribute-name = value • attribute-name—simple name • value—any string • Any attribute and its current value may be suppressed together. Object-Oriented Paradigm and UML
Examples of Object Symbols Object-Oriented Paradigm and UML
Object Diagram Uses • Show the state of one or more objects at a moment during execution • Dynamic models as opposed to class diagrams, which are static models (A static model represents aspects of a program that do not change during execution.) (A dynamic model represents aspects of a program that change during execution.) Object-Oriented Paradigm and UML
UML Diagram Tree Object-Oriented Paradigm and UML
Procedural vs. Object-Oriented Thinking Object-Oriented Paradigm and UML
Stack of int ADT • Carrier set: set of all stacks of ints • Empty stack • #0, #1, #2, … • #00, #01, #10, … • … • Operations: push(), pop(), top(), isEmpty(), isFull(), … Object-Oriented Paradigm and UML
Procedural Approach • Determine a way to represent the elements of the carrier set (a data structure) • Determine how to implement the operations (procedures) • Implement the data structure and procedures in code Object-Oriented Paradigm and UML
C stackOfInt Implementation • stackOfInt.h • stackOfInt.c • main.c Object-Oriented Paradigm and UML
Object-Oriented Approach • Encapsulate the carrier set and the operations in a class • Determine how to implement the carrier set and operations • Implement the class in code Object-Oriented Paradigm and UML
Class Design Object-Oriented Paradigm and UML
C++ IntStack Implementation • IntStack.h • IntStack.cpp • main.c Object-Oriented Paradigm and UML
Example: Ph Monitor • pH sensors in a vat are monitored • A control chart is generated Object-Oriented Paradigm and UML
Procedural Approach • Make a context diagram • Make data flow diagrams • Make ERDs • Make a structure chart • Implement the code Object-Oriented Paradigm and UML
pH Monitor Context Diagram Object-Oriented Paradigm and UML
pH Monitor Data Flow Diagram Object-Oriented Paradigm and UML
pH Monitor Structure Chart Object-Oriented Paradigm and UML
How to describe Requirement Result on OO? • Use UML diagram • Sometime you can use Use Case diagram as the first diagram. • Move into another diagram as needed. Object-Oriented Paradigm and UML
Change Chart Display Chart Collect Sample Use Case Diagram Object-Oriented Paradigm and UML
pH Monitor Class Diagram Object-Oriented Paradigm and UML
Thank you Object-Oriented Paradigm and UML