unit4 desiging classes

15
Designing Classes 1.Designing classes 2.Designing protocols and class visibility 3.The UML object Constraint language 4.Designing methods

Upload: gopal10scs185

Post on 24-Jan-2015

136 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Unit4 desiging classes

Designing Classes

1. Designing classes2. Designing protocols and class visibility3. The UML object Constraint language4. Designing methods

Page 2: Unit4 desiging classes

Introduction

• Designer has to know– Specification of the class– interaction of that class with other classes

Page 3: Unit4 desiging classes

Object oriented design philosophy

• Designing class with reusability in mind -> more gain in productivity and reduce the time for developing new application

Page 4: Unit4 desiging classes

UML Object Constraint Language(OCL)

• The rules and semantics of UML are expressed using OCL• OCL

– Specification language– Uses simple logic to specify the properties of the system

• UML modeling constructs requires expression. some example as follow– Item.selector

• Item -> object• Selector -> attribute• Ex : kathir.regno

– Item.selextor[qualifier-value]• Qualifier is uesd to select related values• Ex:

– Kathir.phone[2]

– Set->select ( Boolean expression)• Company.employee->salary>20000

Page 5: Unit4 desiging classes

Designing classes : process

• Apply design axioms to design calsses , their atribute, methods and association , structures, amd protocols– Refine and complete the static uml class diagrams by

adding details to that design• Refine attribute• Design methods and protocols

– Uses uml activity diagram to represent algorithm

• Refine the association bw classes• Refine class hierarchy and design with inheritance

– Iterate and refine

Page 6: Unit4 desiging classes

Class visibility: desiging well defined public , private and protected protocols

• 2 problems in designing methods or attributes of class– Protocol or interface to the class operation and its

visibility– How it is implemented

• Protocol layers– Private protocol– Protected protocol– Public protocol

Page 7: Unit4 desiging classes

Internal layer

• Defines the implementation of the object• Apply axioms and corollaries ( corollary 1) to

decide what to private• Private protocol– Includes messages that should not be sent from other

objects– Accessible to only operations of that class

• Protected protocol– Methods and attributes can be used by class itself or its

subclass

Page 8: Unit4 desiging classes

External layer

• Design the functionality of the object• Public protocol– Defined to pass message bw associated classes– Interpretation and implementation of each

message is up to the individual classes

Page 9: Unit4 desiging classes

Encapsulation leakage

• lack of well designed protocol leads to this problem

• Encapsulation leakage occurs when details about classes internal implementation are disclosed through the interface

Page 10: Unit4 desiging classes

Refining attribute

• Attribute– Represents the state of the object

• Analysis phase -> name of the attribute is sufficient• Design phase -> detailed information must be added• Attribute types

– Single valued attribute• Ex: dob of the student

– Multiplicity or multivalue attribute• Subjects handled by the staff

– Reference to another object or instance connection• Person hold the account

Page 11: Unit4 desiging classes

UML attribute presentation• OCL is used in the design phase to define the class

attributes• Attribute presentation– Visibility name : type-expression = initial-value– Visibility

• Public visibility: +• Protected visibility : #• Private visibility : -

– Type expression • Language dependent specification of the type

– Initial value• Language dependent expression for the initial value

Page 12: Unit4 desiging classes

Designing methods and protocols• Specifying the algorithm for methods– By using formal structure (ex uml activity diag) with OCL

• Types of methods– Constructor– Destructor– Conversion method– Copy method– Attribute set– Attribute get– IO methods– Domain specific

Page 13: Unit4 desiging classes

Design issues : avoiding pitfalls

• Better to have Large set of simple classes than few large , complex classes– Initially class might be too bid– Apply design axioms and corollary • to reduce the size• Improve reusability

Page 14: Unit4 desiging classes

UML Operation presentation

• Visibility name: (Parameter list ) : return-type-expression – Visibility

• Public visibility : +• Protected visibility : #• Private visibility : -

– Name• Name of the operation

– Parameter list• List of parameters each specified by

– Name : type expression = default value

– Return type expression– Ex:

• + withdraw(amount:type):

Page 15: Unit4 desiging classes

Packaging and managing classes