1 / 68

Workshop for CS-AP Teachers

Workshop for CS-AP Teachers. Chapter 2 Object-Oriented Analysis. Objectives. What is the purpose of analysis? Why should we do object-oriented analysis? What are the things that must be done in analysis? Apply analysis to real-world problems What are some analysis techniques?.

xiang
Download Presentation

Workshop for CS-AP Teachers

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. Workshop for CS-AP Teachers Chapter 2 Object-Oriented Analysis Georgia Institute of Technology

  2. Objectives • What is the purpose of analysis? • Why should we do object-oriented analysis? • What are the things that must be done in analysis? • Apply analysis to real-world problems • What are some analysis techniques? Georgia Institute of Technology

  3. Analysis Purpose • Understand the application domain • An object-oriented program is a simulation of the domain • We can’t create a simulation until we know the domain • Understand the needs of different users • We can’t create software people will use • until we know who wants to use it and what they want to do with it Georgia Institute of Technology

  4. Analysis is Important • O-O development does not mean: “program first, design later” • If you do not understand what users need, writing a program is a waste of time • What are the Analysis Models for? • Aid understanding of the application by both developers and users • Determine the feasibility of a proposed system and the boundaries of the system • Serve as a basis for designing the system Georgia Institute of Technology

  5. Structured Analysis vs. O-O Analysis • Traditional Structured Analysis and Design arose from abstraction from the design of computer hardware • Von Neuman computers: Georgia Institute of Technology

  6. Problems with Structured Analysis • Structured analysis tried to fit people’s problems to computer science solutions • Unfortunately, very few organizations or applications are organized like these solutions! • People are increasingly unwilling to change to accommodate a solution that does not meet their needs • The fundamental problem is that it decouples data and processing. • This makes it difficult to handle changes, clouds understanding, obstructs reuse, and doesn’t scale well. Georgia Institute of Technology

  7. Example of Structured Analysis • Tackling these problems separately is seductively simple • ??? Why is the above structure chart and corresponding structured program difficult to adapt to: • Changes in employee data • New types of employees Georgia Institute of Technology

  8. Why use Object-Oriented Analysis? • The universality of objects in the application domain suggests that they should be the basis for analysis • Focusing on objects helps in understanding the domain • Class names, attributes, and relationships between classes are specified and not assumed • Objects change less than procedures • Easier to localize changes Georgia Institute of Technology

  9. Object-Oriented Analysis • Focuses on problem space understanding • Creates models are potentially intelligible to both users and developers • Treats object attributes and behaviors as indivisible • Reduces coupling in system partitioning • Has an explicit representation of commonality: inheritance • Encapsulate external interfaces using objects • Leads well to object-oriented design Georgia Institute of Technology

  10. Object-Oriented Analysis Process • Identify candidate objects and their classes • What objects are in the domain and their classes? • Document classes • What is a class responsible for? • Determine the relationships between classes • Construct a class diagram • Define the boundaries of the system • What is in your system and what is external? • Identify the users and their goals • Gather high-level use cases Georgia Institute of Technology

  11. OO Analysis Process • These steps can proceed in parallel and are inter-related • Doing one step improves our understanding of and modifies the results of other steps • Therefore analysis is not a linear process Find classes in requirements Gather high-level use cases Revise classes based on use cases Georgia Institute of Technology

  12. Identifying Classes • To identify classes ask what are the things talked about in the domain? • What classes might be found in these domains? • Databases? • Graphical User Interfaces? • ATM (Automatic Teller Machine)? Georgia Institute of Technology

  13. Some Possible ATM Classes Georgia Institute of Technology

  14. Drawing Editor Exercise • Identify the classes for a simple drawing editor. Also show the data and operations for the classes. • The editor can draw rectangles, circles, and triangles. It can show connections between shapes with a a line. The shapes can be erased, moved, and rotated. Georgia Institute of Technology

  15. Drawing Editor Exercise Georgia Institute of Technology

  16. Work Area for Exercise Georgia Institute of Technology

  17. Drawing Editor Class Diagram • What do these classes have in common? • Is any class “a kind of” another class? Rectangle Circle Triangle radius center width height center points center draw() move() draw() move() rotate() draw() move() rotate() Georgia Institute of Technology

  18. Factoring Out a Parent Class • Create the Shape class to factor out common behavior and data Shape center draw() move() rotate() abstract abstract {do nothing} Circle Rectangle Triangle radius width height points draw() move() draw() move() draw() move() Georgia Institute of Technology

  19. Defining Methods in the Base Class • By defining some of the operations in Shape as abstract we can define the erase and move methods. Shape center draw() move() rotate() erase() abstract {erase self set center draw self} {do nothing} {set bg color draw self} Circle Rectangle Triangle radius width height points draw() draw() rotate() draw() rotate() Georgia Institute of Technology

  20. Display List • A display list maintains an ordered list of Shapes DisplayList :aDisplayList shapeList draw()hit?() :aCircle :aRectangle :aRectangle :aTriangle Georgia Institute of Technology

  21. Drawing the Display List • When the display list gets the message draw • It delegates the work by simply sending each of the shape objects in the list the message draw starting with the shape on the bottom draw() :aDisplayList (1) draw() (4) draw() (3) draw() (2) draw() :aCircle :aRectangle :aRectangle :aTriangle Georgia Institute of Technology

  22. Identify the Objects / Classes • What is an Object? • An entity that knows something (attributes) and can do something (operations). An object is an instance of a class. • For example: Account, Queue, Flight, Transaction Georgia Institute of Technology

  23. Identify Classes • Finding the Classes • Examine the System Requirements • Interview Users - when in doubt go back to the user! • Examine other documents in the domain (databases, forms, external systems, …) • What are the things doing the action or being acted upon? item Georgia Institute of Technology

  24. The “Noun” Algorithm • Examine the requirements and underline the nouns and verbs • The nouns are candidate classes or attributes • The verbs are candidate methods • An object that receives a message needs to have a matching method • Shapes can be rotated means sending a rotate message to shape. rotate shape.rotate() Georgia Institute of Technology

  25. CRC Cards • Class – Responsibility – Collaborator • developed by Ward Cunningham and Kent Beck at Tektronix in the late 1980’s as a way to teach object-oriented analysis and design • Manual Object-Oriented Analysis Technique • 3x5 index cards (originally 4 x 6 cards) Classname Responsibilities Collaborators Georgia Institute of Technology

  26. Use and Advantages • Used to • Record classes as they are identified • Record the purpose (responsibility) of each class • Record and experiment with relationships (collaborators) between classes • Advantages • cheap, portable, readily available, and familiar • focus on analysis, not on a diagram • good in a group discussion Georgia Institute of Technology

  27. CRC Cards Format • Classname • Responsibilities: a textual description of the purpose of the class • Collaborators: list the names of the classes that this class must work with to accomplish the responsibilities Classname Responsibilities Collaborators Georgia Institute of Technology

  28. Suggestions for Use • Use early in the analysis for brainstorming all the possible objects. • Focusing on responsibilities helps clarify the essential nature of a class • It is easy to throw a card away • Position the cards when trying to figure out the class relationships • subclasses • close collaboration Georgia Institute of Technology

  29. CRC Cards Example • Do an analysis of a hotel room reservation system. • The system must allow clerks to assign rooms to customers. It must also allow clerks to assign maids to clean the rooms. Clerk Customer Maid Room Georgia Institute of Technology

  30. CRC Cards Example Clerk Customer Customer Maid Stays in hotel Room Clerk Checks customer in and out Manages maids Maid Room Customer Maid Cleans room Room Clerk Place for customer to stay Georgia Institute of Technology

  31. CRC Card Example Clerk Customer Customer Maid Stays in hotel Check in Check out Pay for room Use phone Room Clerk Checks customer in and out Assigns room Handles payment Manages maids Assigns room Maid Room Customer Maid Cleans room Assigned room Cleans room Room Clerk Place for customer to stay Georgia Institute of Technology

  32. Solitaire Exercise • Do an analysis of Solitaire • First play the game • Print off the “How to Play” help • Underline the nouns and verbs • Create CRC Cards for the nouns • What is each class responsible for? • What other classes does each class need to work with? Georgia Institute of Technology

  33. Unified Modeling Language - UML • After Smalltalk was released in 1980 several big companies started work in it • IBM, Apple, DEC, Tektronix • People needed a way to talk about objects • Created diagrams to represent classes, the relationship between classes, object and class attributes and methods, and interactions between objects • By the late 80’s early 90’s there were many similar but different types of diagrams • Now there is one standard graphical language: UML Georgia Institute of Technology

  34. What is the UML? • Unified Modeling Language • Graphical language for visualizing, specifying, constructing, and documenting object-oriented systems • Meta-model with rigorous specification • Created by Rational • Grady Booch, Ivar Jacobson, Jim Rumbaugh • the three amigos • Originally merged their three different approaches • Revisions are done by an OMG task force • UML Specification • http://www.omg.org/technology/documents/formal/uml.htm Georgia Institute of Technology

  35. UML Diagrams • Class Diagram • Shows classes and the relationships between them • Can be used to create package diagrams • Use Case Diagram • Shows the desired functionality of the system • Behavior Diagrams • Statechart Diagram • Good for modeling objects that change state • Activity Diagram • Models workflow or business processes Georgia Institute of Technology

  36. UML Diagrams - Continued • Behavior Diagrams: (continued) • Interaction Diagrams: • Sequence Diagram • Shows messages between objects in a sequential way • Collaboration Diagram • Shows messages between objects in a compact way • Implementation Diagrams: • Component Diagram • Shows the organization of software components • Deployment Diagram • Shows how packages of classes are deployed on machines Georgia Institute of Technology

  37. Why Create Diagrams? • Blueprints for constructing large software systems • Would you want to live in a large building that was built without a blueprint? • Advantages to Diagrams • Show System Architecture • Verify soundness and completeness • Improve Communication • Between developers • Between developers and users • Simplify Complexity • Reduce ambiguity Georgia Institute of Technology

  38. Drawbacks to Diagrams • Tedious to create • Easier if you use a tool • Tedious to modify • Depends on tool • Tend to get out of date • Reverse engineering tools can help with this • Slow development • Too much time diagramming, not enough developing Georgia Institute of Technology

  39. UML Tools • Popular Tools • Rational Rose – www.rational.com • Market leader but expensive • Together Control Center - www.togethersoft.com • Moderate cost • Visio 2002 - www.microsoft.com/office/visio • Moderate cost • Magic Draw - www.magicdraw.com • Low cost • Links to sites that list UML Tools is at • http://www.omg.org/technology/uml/index.htm#Links-Methodologies Georgia Institute of Technology

  40. Some UML Tools Capabilities • Create and modify diagrams • Generate code from diagrams • Reverse engineer diagrams from code • Generate a database definition • Create DDL for relational databases • Generate HTML documentation • Save diagrams in XMI (XML Metadata Interchange) • For exchange with other tools Georgia Institute of Technology

  41. Class Diagram • Shows classes and the relationships between them • Static structure • Not time dependent • Most important and commonly used diagram in UML Georgia Institute of Technology

  42. Class Representation • Rectangles are used to represent classes • There are different sections for the class name, attributes and operations Class Name Dog Attribute1 Attribute2 size shape Operation1() Operation2() wagTail() bark() Georgia Institute of Technology

  43. Visibility • Who can access the item • Types of Visibility • Public (+) • All can use • Private (-) • Only objects of the class • Protected (#) • Objects of the class and objects of subclasses • Attributes should be private • So the object has control of its’ data • Or protected if subclasses need quick access • Methods are public or private • Public if intended as a service. Private if for internal use Georgia Institute of Technology

  44. Static Class Relationships • Association • has-a • A connector has shapes • Generalization • is-a-kind-of • More precise than is-a • A circle is a kind of shape • Aggregation • is-a-part-of • A display list is an aggregation (collection) of shapes • Composition • Is-an-integral-part-of • the whole lives or dies with the parts Georgia Institute of Technology

  45. Dynamic Class Relationship • Dependency • Uses • A car uses a parking space • It doesn’t have a have-a relationship with it • Dynamic relationships are relationships that change over time Georgia Institute of Technology

  46. Association Multiplicities • Associations have multiplicities (one for each end) • X can have how many objects of y associated with it? • Y can have how many objects of x associated with it? • Kinds of Multiplicities • m..n • Inclusive range from m to n • n • There must be exactly n • * or 0..* • 0 to many • 1,3,5 • May be 1 or 3 or 5 Georgia Institute of Technology

  47. Roles • Each association end is a role • role A • role B • Roles can be explicitly named • Especially useful when there is more than one association between the classes • Or for use in generated code Georgia Institute of Technology

  48. Class Diagram Perspectives • There are three perspectives that a class diagram can represent • Conceptual - Analysis Stage • Language independent, represents the domain • Specifies the classes, some attributes, some operations, and the relationships between classes • Specification - Design Stage • Represents a high level design of the solution • Classes in the diagram are more fleshed out • Implementation – Programming Stage • Represents the actual solution • Shows attributes, operations, types (if needed), and parameters to operations Georgia Institute of Technology

  49. Solitaire Class Diagram Georgia Institute of Technology

  50. When is Something not an Object? • Objects have three important characteristics • State: data about the object, like its color or size • Behavior: operations that can be performed on the object • Identity: distinct boundaries that identify what is part of the object • Some nouns are attributes • Simple scalar items like strings and numbers • Some nouns describe the user interface • Don’t focus on interface in analysis • Some nouns are external • Use the system but are not needed in it Georgia Institute of Technology

More Related