CSC 340 Tutorial 7 System Design TA Y

  • Slides: 21
Download presentation
CSC 340: Tutorial 7 System Design TA: Y. An Date: 9: 00 -10: 00

CSC 340: Tutorial 7 System Design TA: Y. An Date: 9: 00 -10: 00 am, Fri. Nov 21, 2003 Location: BA 1130 2021/5/19 CSC 340 1

Object Design n n Specification of attribute types, how operations function and how objects

Object Design n n Specification of attribute types, how operations function and how objects are linked to other objects. Design criteria: ¡ ¡ ¡ 2021/5/19 Visibility Coupling and cohesion Association Integrity constraints Data normalization CSC 340 2

Attribute and Operation Signatures n n An attribute’s data type is declared in UML

Attribute and Operation Signatures n n An attribute’s data type is declared in UML using the following syntax: name’: ’typeexpression ‘=‘ initial-value ‘{‘ propertystring ‘}’, e. g. , balance: Money=0. 00 An operation’s syntax as follows: operation name ‘(‘ parameter-list ‘)’ ‘: ’ return-typeexpression, e. g. , credit(amount: Money): Boolean 2021/5/19 CSC 340 3

n Visibility to enforce encapsulation. + - Public Private # protected 2021/5/19 CSC 340

n Visibility to enforce encapsulation. + - Public Private # protected 2021/5/19 CSC 340 4

Interfaces n n An interface in UML is a group of externally visible operations.

Interfaces n n An interface in UML is a group of externally visible operations. An interface has no attributes, no associations and the implementation of the operations is not defined. The simpler of the interface notation is a circle. Alternatively, use a stereotyped class icon. 2021/5/19 CSC 340 5

Two Types of Interface Notations 2021/5/19 CSC 340 6

Two Types of Interface Notations 2021/5/19 CSC 340 6

Coupling and Cohesion n n Coupling describes the degree of interconnectedness between design components

Coupling and Cohesion n n Coupling describes the degree of interconnectedness between design components and is reflected by the number of links an object has and by the degree of interaction the object has with other object. Cohesion is a measure of the degree to which an element contributes to a single purpose. 2021/5/19 CSC 340 7

Classification of Coupling n n Interaction coupling: a measure of the number of message

Classification of Coupling n n Interaction coupling: a measure of the number of message types an object sends to other objects and the number of parameters passed with these message types. It should be kept to minimum. Inheritance coupling: the degree to which a subclass actually needs the features it inherits from its base class. 2021/5/19 CSC 340 8

Poor Inheritance Coupling n n Poor inheritance coupling causes an object take more memory

Poor Inheritance Coupling n n Poor inheritance coupling causes an object take more memory and may cause maintenance problem. Poor inheritance coupling causes false requirement interpretation. 2021/5/19 CSC 340 9

Classification of Cohesion n Operation cohesion: the degree to which an operation focuses on

Classification of Cohesion n Operation cohesion: the degree to which an operation focuses on a single functional requirement. Good design produces highly cohesive operations. Class cohesion: the degree to which a class is focused on a single requirement. Specialization cohesion: the semantic cohesion of inheritance hierarchies. 2021/5/19 CSC 340 10

Good and Poor cohesion n n Good design produces highly cohesive operations, each of

Good and Poor cohesion n n Good design produces highly cohesive operations, each of which deals with a single functional requirement, e. g. , calculate. Room. Space() Poor class cohesion adds inappropriate attributes. 2021/5/19 CSC 340 11

High Coupling and Low Cohesion n n The hierarchy has high inheritance coupling. However,

High Coupling and Low Cohesion n n The hierarchy has high inheritance coupling. However, it is neither true that a person is a kind of address, nor is a company. It has low specialization cohesion. 2021/5/19 CSC 340 12

A Better Design n A better design in which a common class Address is

A Better Design n A better design in which a common class Address is being used by both the Person and Company classes. 2021/5/19 CSC 340 13

Liskov Substitution Principle n n LSP states that in object interactions, it should be

Liskov Substitution Principle n n LSP states that in object interactions, it should be possible to treat a derived object as if it were a base object. The debit operation in left is declared as private, hence cannot be used by any other object. 2021/5/19 CSC 340 14

One-way one-to-one association n n An association link provides the connection necessary for message

One-way one-to-one association n n An association link provides the connection necessary for message passing to occur. How to implement an association is important to analyze the message passing between the objects tied by the association. 2021/5/19 CSC 340 15

On to Many Association n 2021/5/19 CSC 340 Handling a group of Advert objects

On to Many Association n 2021/5/19 CSC 340 Handling a group of Advert objects is to place them in a separate object, a collection object that has operations to manage the object identifiers and that behaves rather like an index of adverts for the campaign object. 16

Sequence of Interaction for the Collection Object 2021/5/19 CSC 340 17

Sequence of Interaction for the Collection Object 2021/5/19 CSC 340 17

Many to Many association n 2021/5/19 CSC 340 Using two collection objects to handle

Many to Many association n 2021/5/19 CSC 340 Using two collection objects to handle the two-way manyto-many association. 18

Integrity Constraints n n Analysis may have identified a series of integrity constraints that

Integrity Constraints n n Analysis may have identified a series of integrity constraints that have to be enforced. Referential integrity: ensures that an object identifier in an object is actually referring to an object that exists. Dependency constraints: ensures that attribute dependencies, where one attribute may be calculated from other attributes. Domain integrity: ensures that attributes only hold permissible values. 2021/5/19 CSC 340 19

Dependency Constraint n Dependency constraints can also exist between or among associations. One of

Dependency Constraint n Dependency constraints can also exist between or among associations. One of the simplest cases is shown as above: chairs association is a subset of the is. AMember. Of association. 2021/5/19 CSC 340 20

Recap n Criteria of object design: ¡ ¡ ¡ 2021/5/19 Visibility: public, private, protected.

Recap n Criteria of object design: ¡ ¡ ¡ 2021/5/19 Visibility: public, private, protected. Interface: a group of externally visible operations. Coupling and cohesion: interaction coupling, inheritance coupling, operation cohesion, class cohesion, specialization cohesion. Liskov substitution principle: derived object can be treated as base object. Implement associations: one-to-one, one-to-many, manyto-many: using a collection object. Integrity constraints: referential, dependency, and domain constraints. CSC 340 21