Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 1 Chapter 14 Object-Oriented Design.

Similar presentations


Presentation on theme: "©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 1 Chapter 14 Object-Oriented Design."— Presentation transcript:

1 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 1 Chapter 14 Object-Oriented Design

2 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 2 Objectives l To explain how a software design may be represented as a set of interacting objects that encapsulate their own state and operations. l To describe (and illustrate) the activities in the object-oriented design process. (cont’d)

3 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 3 Objectives (cont’d) l To introduce various models used to describe an object-oriented design l To show how the UML may be used to represent these models

4 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 4 Topics covered l Characteristics of OOD l History of OOD as reflected by Sommerville l Objects and object classes l Generalization and inheritance l An object-oriented design process (Weather Station example) l Design evolution

5 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 5 Characteristics of OOD l Allows designers to think in terms of interacting objects that maintain their own state and provide operations on that state instead of a set of functions operating on shared data. l Objects hide information about the represen- tation of state and hence limit access to it. l Objects may be distributed and may work sequentially or in parallel.

6 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 6 A design strategy based on “information hiding”… Another way to think about “information hiding”: Potentially changeable design decisions are isolated (i.e., “hidden”) to minimize the impact of change. - David Parnas (Is there any connection between information hiding and AOSD?)

7 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 7 Interacting objects

8 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 8 Advantages of OOD l Easier maintenance. Objects may be understood as stand-alone entities (and ripple effect is reduced). l Objects are appropriate reusable components. l For some systems, there is an obvious mapping from real world entities to system objects.

9 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 9 Object-oriented development l OO Analysis: concerned with developing an object model of the application domain. l OO Design: concerned with developing an object-oriented system model to implement requirements l OO Programming: concerned with realising an OOD using an OO pro- gramming language such as Java or C++.

10 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 10 The history of OO Development as reflected by Sommerville’s text l 1 st Edition (1982): No mention of OO design! l 2 nd Edition (1985): …it has been sug- gested that a better design methodology is OO design… To place such comments in perspective, many large systems have been built using top-down design. Few large systems have been built using an object-oriented approach.

11 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 11 The history of OO Development as reflected by Sommerville’s text l 3 rd Edition (1989): It is only within the past few years that an alternative mode of decomposition, OO design, has been recognized as of value. l 4 th Edition (1992): OO methods are still relatively immature and are changing rapidly so are not nearly as widely used as methods based on functional decomposition. They will become more widely used as they mature…

12 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 12 The history of OO Development as reflected by Sommerville’s text l 5 th Edition (1995): Until relatively recently, the most commonly used software design strategy involved decomposing the design into functional components with system state information held in a shared data area…It is only since the late 1980’s that…OO design has been widely adopted.

13 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 13 The history of OO Development as reflected by Sommerville’s text l 6 th Edition(2001): An OO approach to the whole (of) software development is now commonly used… Coverage of functional design is now included in the new chapter on legacy systems.

14 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 14 The history of OO Development as reflected by Sommerville’s text l 7 th Edition (2004): Chapter on legacy systems deleted. Although many software developers consider function-oriented design to be an outdated approach, OO development may not offer significant advantages (in some) situations. An interesting challenge…is to ensure that function- oriented and OO systems can work together.

15 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 15 The history of OO Development as reflected by Sommerville’s text l 8 th Edition (2007): Chapter on Aspect- Oriented Software Development added. In most large systems...implementing a change to a requirement may involve understanding and changing many components... AOSD is an emerging approach...intended to address this problem. Aspects are used alongside other abstractions such as objects and methods. (AOSD) support separating concerns into independent elements...

16 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 16 Should we still be placing an emphasis on OO Design? l Extensive up-front design can be criticized because the extensive analysis and design effort is not well suited to incremental development and delivery. l Agile methods have been developed to address this problem. (cont’d)

17 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 17 Should we still be placing an emphasis on OO Design? (cont’d) l Sommerville's view: extensive, “heavy- weight” design is unnecessary for small and medium-sized systems. But for large systems, particularly critical systems, it is essential to ensure that teams working on different parts of the system are properly coordinated.

18 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 18 Objects and object classes l Objects are entities with state and a defined set of operations on that state.  State is represented as a set of object attributes.  Operations provide services to other objects when requested.

19 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 19 Objects and object classes (cont’d) l Object classes are templates for objects.  An object class definition includes declarations of all attributes and operations associated with an object of that class.  They may inherit attributes and services from other object classes.

20 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 20 The Unified Modeling Language l Several different notations for OOD were proposed in the 1980s and 1990s. (Booch, Rumbaugh, Jacobson, Coad & Yourdon, Wirfs, …) l UML is an integration of these notations. l It describes a number of different models that may be produced during OO analysis and design (user view, structural view, behavioural view, implementation view, …) l The de facto standard for OO modelling.

21 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 21 Employee object class (UML) Object attributes Services to other objects

22 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 22 Object communication l Conceptually, objects communicate by message passing. l Messages include:  The name of the service requested,  A copy of the information required to carry out the service, and  the name of a holder for the result of the service. l In practice, messages are often imple- mented by procedure calls

23 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 23 Message examples // Call a method associated with a buffer // object that returns the next value // in the buffer v = circularBuffer.Get () ; // Call the method associated with a // thermostat object that sets the // temperature to be maintained thermostat.setTemp (20) ; Info required Name of service Holder for result (cf. XML text messages in service-based systems)

24 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 24 Generalization and inheritance l Objects are members of classes which define attribute types and operations. l Classes may be arranged in a hierarchy where one class (a super-class) is a generalization of one or more other classes (sub-classes)

25 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 25 Generalization and inheritance l A sub-class inherits the attributes and operations from its super class and may add new methods or attributes of its own.

26 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 26 A UML generalisation hierarchy Definition on slide 21

27 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 27 Advantages of inheritance l It is an abstraction mechanism which may be used to classify entities. l It is a reuse mechanism at both the design and the programming level. l The inheritance graph is a source of organizational knowledge about domains and systems. (OO Analysis)

28 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 28 Problems with inheritance l Object classes are not self-contained (i.e., they cannot be understood without reference to their super-classes). l Designers have a tendency to reuse the inheritance graph created during analysis. (Inheritance graphs of analysis, design and implementation have different functions.) Due to inherited attributes/ops Discipline/education problem?

29 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 29 Inheritance and OOD l Inheritance is a useful implementation concept which allows reuse of attribute and operation definitions. l Some feel that identifying an inheritance hierarchy or network is also a funda- mental part of object-oriented design. (Obviously, this can only be implemented directly using an OOPL.) (cont’d)

30 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 30 Inheritance and OOD (cont’d) l Others feel this places unnecessary restrictions on the implementation.* l Inheritance introduces complexity and this is undesirable, especially in critical systems. (where design transparency is of utmost importance) * This appears to be Sommerville’s view

31 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 31 UML associations l Objects and object classes participate in various types of relationships with other objects and object classes. l In the UML, a generalized relationship is indicated by an association. (cont’d)

32 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 32 UML associations (cont’d) l Associations may be annotated with information that describes their nature. l Associations can be used to indicate that an attribute of an object is an associated object or that a method relies on an associated object. (semantics)

33 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 33 An association model annotations

34 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 34 Concurrent objects l The nature of objects as self-contained entities make them well suited for con- current implementation. l The message-passing model of object communication can be implemented directly if objects are running on separate processors in a distributed system. (as opposed to using procedure calls) (e.g., as XML text messages in service-based systems)

35 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 35 Concurrent object implementation: servers and active objects l Servers (Passive objects): entry points correspond to object operations. If no calls are made to it, the object suspends itself and waits for further requests for service. l Active objects: internal object state may be changed by the object itself and not simply by external calls.

36 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 36 Example: an active transponder object l A transponder object broadcasts an aircraft’s position. (on demand) l The object periodically updates the position by triangulation from satellites. (autonomously)

37 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 37 An active transponder object ON DEMAND IN BACKGROUND Java-based interface description

38 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 38 Active object implementation: Java threads, Ada tasks, etc. l Threads in Java are a simple construct for implementing concurrent objects. l Threads must include a method called run() and this is started up by the Java run-time system. l Active objects typically include an infinite loop so that they are always carrying out the computation.

39 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 39 An object-oriented design process (an iterative, boot-strapping process)

40 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 40 An object-oriented design process (an iterative, boot-strapping process) 1.Define the context and modes of use of the system. 2.Design the system architecture. 3.Identify the principal system objects. 4.Develop design models (static and dynamic). 5.Specify object interfaces.

41 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 41 Weather system description A weather data collection system is required to generate weather maps on a regular basis using data collected from remote, unattended weather stations and other data sources such as weather observers, balloons and satellites. Weather stations transmit their data to the area computer in response to a request from that machine.

42 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 42 Weather system description The area computer validates the collected data and integrates it with the data from different sources. The integrated data is archived and, using data from this archive and a digitized map database, a set of local weather maps is created. Maps may be printed for distribution on a special-purpose map printer or may be displayed in a number of different formats.

43 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 43 Weather station description A weather station is a package of software controlled instruments which collects data, performs some data processing and transmits this data for further processing. The instruments include air and ground thermometers, an anemometer, a wind vane, a barometer and a rain gauge. Data is collected every five minutes.

44 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 44 Weather station description When a command is issued to transmit the weather data, the weather station processes and summarises the collected data. The summarised data is transmitted to the mapping computer when a request is received.

45 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 45 An object-oriented design process (an iterative, boot-strapping process) 1.Define the context and modes of use of the system. 2.Design the system architecture. 3.Identify the principal system objects. 4.Develop design models (static and dynamic). 5.Specify object interfaces.

46 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 46 1.Define system context and modes of use l Goal: develop an understanding of the relationships between the software being designed and its external environment. l System context: a static model that describes other systems in the environ- ment. l The context of the weather station is illustrated below using UML packages.

47 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 47 Context of weather station

48 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 48 1.Define system context and modes of use (cont.) l Modes of system use: a dynamic model that describes how the system will interact with its environment. l Modes of weather station use are illustrated below using a UML use-case model.

49 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 49 Use-cases for the weather station External entity (weather data collection sys) Possible interactions

50 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 50 Use-case description basis for “information hiding”

51 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 51 An object-oriented design process (an iterative, boot-strapping process) 1.Define the context and modes of use of the system. 2.Design the system architecture. 3.Identify the principal system objects. 4.Develop design models (static and dynamic). 5.Specify object interfaces.

52 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 52 2.Design system architecture l A layered architecture is appropriate for the weather station:  Interface layer for handling communications  Data collection layer for collecting and summarizing weather data  Instruments layer for encapsulating instruments used to collect raw data l Rule of Thumb: There should be no more than 7 entities in an architectural model. (See Miller, "The Magical Number Seven, Plus or Minus Two,“ WOR. )

53 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 53 Weather station architecture UML “nested packages” UML annotations

54 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 54 An object-oriented design process (an iterative, boot-strapping process) 1.Define the context and modes of use of the system. 2.Design the system architecture. 3.Identify the principal system objects. 4.Develop design models (static and dynamic). 5.Specify object interfaces.

55 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 55 3.Identify principal system objects l Identifying objects (or object classes) is the most difficult part of OO design. l There is no “magic formula” – it relies on the skill, experience, and domain knowledge of system designers l An iterative process – you are unlikely to get it right the first time.

56 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 56 Approaches to object identification l Use a grammatical approach based on a natural language description of the system (Abbott’s heuristic). l Associate objects with tangible things in the application domain (e.g. devices). l Use a behavioural approach: identify objects based on what participates in what behaviour. (cont’d)

57 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 57 Approaches to object identification (cont.) l Use scenario-based analysis. The objects, attributes and methods in each scenario are identified. l Use an information-hiding based approach.* Identify potentially change- able design decisions and isolate these in separate objects. * “Bonus” approach! (No extra charge.)

58 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 58 Weather station object classes l Weather station – interface of the weather station to its environment. It reflects interactions identified in the use-case model. l Weather data – encapsulates summarised data from the instruments. l Ground thermometer, Anemometer, Barometer – application domain “hardware” objects* related to the instruments in the system. * hardware-controlling SOFTWARE

59 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 59 Weather station object classes

60 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 60 Other objects and object refinement l Use domain knowledge to identify more objects, operations, and attributes.  Weather stations should have a unique identifier.  Weather stations are remotely situated so instrument failures have to be reported automatically. Therefore, attributes and operations for self-checking are required.

61 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 61 Other objects and object refinement (cont.) l Active or passive objects?  Instrument objects are passive and collect data on request rather than autonomously. This introduces flexibility (how?)* at the expense of controller processing time.  Are any active objects required? * Hint: consider potentially changeable design decisions

62 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 62 An object-oriented design process (an iterative, boot-strapping process) 1.Define the context and modes of use of the system. 2.Design the system architecture. 3.Identify the principal system objects. 4.Develop design models (static and dynamic). 5.Specify object interfaces.

63 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 63 4.Develop design models l Design models show the relationships among objects and object classes.  Static models describe the static structure of the system in terms of object and object class relationships.  Dynamic models describe the dynamic interactions among objects.

64 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 64 Examples of design models l Sub-system models show logical groupings of objects into coherent sub- systems. (static) l Sequence models show the sequence of object interactions associated with system uses. (dynamic) (cont’d)

65 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 65 Examples of design models (cont’d) l State machine models show how indi- vidual objects change their state in re- sponse to events. (dynamic) l Other models include use-case models, aggregation models, generalisation (inheritance) models, etc.

66 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 66 Subsystem models l In the UML, these are shown using packages, an encapsulation construct. l This is a logical model – the actual organization of objects in the system as implemented may be different.

67 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 67 Weather station subsystems Annotations go here Active object

68 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 68 Sequence models l Objects are arranged horizontally across the top. l Time is represented vertically; models are read top to bottom. l Interactions are represented by labelled arrows – different styles of arrows represent different types of interaction. l A thin rectangle in an object lifeline represents the time when the object is the controlling object in the system.

69 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 69 Data collection sequence Return of control No reply expected area computer

70 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 70 Weather station state machine model

71 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 71 An object-oriented design process (an iterative, boot-strapping process) 1.Define the context and modes of use of the system. 2.Design the system architecture. 3.Identify the principal system objects. 4.Develop design models (static and dynamic). 5.Specify object interfaces.

72 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 72 5.Object interface specification l Designers should avoid revealing data representation information in their interface design. (operations access and update all data) l Objects may have several logical interfaces which are viewpoints on the methods provided. (supported directly in Java) l The UML uses class diagrams for interface specification but pseudocode may also be used.

73 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 73 Weather station interface (Java-based)

74 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 74 Design evolution l Hiding information in objects means that changes made to an object need not affect other objects in an unpredictable way. l Assume pollution monitoring facilities are to be added to weather stations. l Pollution readings are transmitted with weather data.

75 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 75 Changes required l Add an object class called “Air quality” as part of WeatherStation. l Add an operation reportAirQuality to WeatherStation. Modify the control software to collect pollution readings. l Add objects representing pollution monitoring instruments. …and that’s all.

76 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 76 Pollution monitoring

77 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 77 l OOD results in design components with their own private state and operations. l Objects should have constructor and inspection operations. They provide services to other objects. l Objects may be implemented sequentially or concurrently. l The Unified Modeling Language provides different notations for defining different object models. Key points as do algebraic specs (cont’d)

78 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 78 Key points (cont’d) l A range of different models may be produced during an object-oriented design process. These include static and dynamic system models (See the OMG website for sources.) l Object interfaces should be defined precisely. l Object-oriented design simplifies system evolution.

79 ©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 79 Chapter 14 Object-Oriented Design


Download ppt "©Ian Sommerville 2000 Software Engineering. Chapter 14Slide 1 Chapter 14 Object-Oriented Design."

Similar presentations


Ads by Google