39
Revision Session 3 Adding the detail and design for re-use

Revision Session 3 Adding the detail and design for re-use

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Revision Session 3

Adding the detail and design for re-use

2. Detailed software specifcation• What are operation specifications used for in

systems analysis? – Used to describe the detailed behaviour of the

system.

– adds detail and precision so that user can check if requirements are met. E.g. what to check before debiting a bank account?

– Provides more detail for software design and helps in coding.

Discuss, with the aid of examples, some different ways of specifying operations, both declarative and procedural.

• Using Contracts– Intent or purpose of the operation– Operation signature : parameters and return type– Description of the logic– Other operations called– Events transmitted to other objects– Response to exceptions

• - give an example to show you understand

Non-algorithmic (Declarative )methods

• Describe the logic of the operation as a black box.

• Show Operation Signatures or message protocols

• useful where a structured decision has to be made- the description is used to determine the conditions that determine the outcome.

• E.g. decision tables, pre and post conditions, OCL (Object Constraint Language )

Decision TablesA decision table is a matrix that shows the conditions under

which a decision is made, the actions which can result and how the two are related.

Steps in Drawing a Decision Table1. List all conditions2. List all possible actions3. Fill in true/false values4. Assign actions 5. Ensure all possibilities have been covered.

• These are useful for situations where there are many outcomes depending on various combinations of input conditions.

Decision Table example – register student on water safety

RULE 1 RULE 2 RULE 3

Conditions

Has student the prerequisite qualification?

Y N Y N

Is student old enough? Y Y N N

Action

Register Student x

Register on prerequisite (if qualified and old enough)

x x

Repeat or put on endurance training

x

• Precondition : what is true/must be true before the method or operation is executed

• Postcondition: what is true/must be true after the method or operation is executed.

Example : enrol(student, module)

Precondition• <student and module objects valid AND space

in module>enrol(student, module)

Postcondition• < enrolment object created>

Object Constraint Language (OCL)

This is used if a much more formal and precise specification is needed. This is a language with a strict syntax used to specify, for example, pre and post conditions.

Algorithmic methods

• Algorithm- describes the internal logic of a process or decision by breaking it down into small steps.

• Uses sequence, selection, iteration and recursion

Example Approaches • Structured English/pseudocode• Activity diagrams, flowcharts

• An operation is required to calculate a plane fare. First class passengers are charged the first class fare and have 20kg baggage free and free seat pre-booking. Above 20kg they are charged €2 per kilo over and €20 per large item like golf clubs. Normal passengers pay €2 per kilo for all baggage and and €20 per large item like golf clubs. They may pre-book a seat but will pay €5 for this.

• Write an operation specification for the above operation using an appropriate method or combination of methods. You are also required to justify your particular choice of method/methods.

1. Need to identify method(s) e.g. operation signature specifies operation as a black box, decision table shows internal logic.

2. Say why you’ve picked these– here we use a decision table because we want to specify actions to be taken based on a series of conditions. Decision tables are useful for situations where there are many outcomes depending on various combinations of input conditions.

3. Draw the table

Need to specify operation signature

• Calculateplanefare (passengerclass: pclass, baggagewgt:float,largeitems:int,reservedseat:boolean):money

• What does this operation need to know to calculate a plane fare?

• What does it return?• [ what does it do?]• Are there any significant pre and post conditions?• What kind of object would this operation belong to?

• Identify actions (red) and conditions (green)

• An operation is required to calculate a plane fare. First class passengers are charged the first class fare and have 20kg baggage free and free seat pre-booking. Above 20kg they are charged €2 per kilo over and €20 per large item like golf clubs. Normal passengers pay €2 per kilo for all baggage and and €20 per large item like golf clubs. They may pre-book a seat but will pay €5 for this.

Algorithmic method ?If (passclass === first) {

fare = firstclassfare;IF ( baggage>20) THEN{ fare = fare + (baggage-20)*2;}IF (largeitem >0 ) THEN{Fare = fare+(largeitems*20)}}Else{…………………………}

Discuss three approaches to software reuse.

• Import existing components or structures from beyond the project boundaries (e.g. re-use of platform-specific components e.g. .Net).• Reuse components of current project-

identify existing components or design with re-use in mind.• Design new components for use within

other projects.

Refinement of software specification can be done through :

(i) abstracting common elements i.e. identifying where you can use generalisation/inheritance) and

(ii) the encapsulation of composite structures and components.

Discuss the meaning of the following concepts, for each indicating how it can contribute to quality software development:1. Generalisation (inheritance)2. Encapsulation3. Components4. Patterns

Inheritance/generalisation

• identifying those aspects of a design that are relevant to more than one situation and redesigning your classes to put the common aspects in a parent class and the specific aspects in a child class.

• Abstract classes are parent classes which have no members in themselves but specify common aspects of a number of (concrete) child classes which can be reused easily.

• ISA –IS A KIND OF is the key relationship here.• Enables easy software modification and re-use, thus

contributing to reusability, extensibility

Generalisation- identifying commonalities-behaviour or attributes

e.g.• What do trainers, students, examiners have in

common?• They are all water safety members, and have an

ID, name,address etc. and may have 0 or more qualification

• What do chance and community chest have in common?

• What do utilities, train stations and other properties have in common?

2. Encapsulation • design software that can be used as a black box

component.• To use it you only need to know how the interface works –

not the implementation.• This means that you can have different implementations

for the same interface, which could be useful, for example in porting an application to different platforms, or using different forms of data storage.

• The focus is on the external behaviour, but ignoring the detail of how that behaviour is produced.

• Enables software that is more maintainable, as change is localised, and portable as implementation can be hidden.

Example : property listClass propertylist

-properties:property[]-nproperties:int

Findfirst():propertyGetnext():propertyAddproperty(P: property)Removeproperty(propertyID:string):booleanFindproperty(propertyID:string)Getproperties():booleanSaveproperties():boolean

Note that to use this class that we do not need to know how it does things e.g. how properties are got or saved, we just need to know each operations signature.

Encapsulation/Composition

• involves encapsulating a group of classes that have the capacity to be a re-usable subassembly.

• The relationship here is ISA Part Of. • Composition – is made up of ... A car has an

engine• Aggregation- can have 0 or more – sand grains

on the beach

Example- design re-usable assemblies

• A newspaper advert can be composed of copy(text), graphics and a photograph.

GraphicsNewspaperAdvert

Text

Photo

0..* 1..*

1..*

0..*

1..*

1..*

3. Components

• Relatively complex structures developed separately to be plugged together.

• Meet a clear-cut but general need.• Have more than 1 simple well-defined

external interfaces.

UML Support for Modelling Components

• Component A has a provided interface which offers services to components that know how to request those services.

• Component B has a required interface which requests services from a provided interface on another component. (basically it will send a message using a defined operation and parameters frpm some provided interface).

Ball and socket diagram.

Component A Component B

• In UML, a component diagram provides a physical view of the system. Its purpose is to show the dependencies that the software has on the other software components (e.g., software libraries) in the system.

• The diagram can be shown at a very high level, with just the large-grain components, or it can be shown at the component package level i.e. class container levels such as .NET's namespaces (e.g., System.Web.UI).

Component-Based Development

• The classes that comprise an individual component need to be identified, modelled, specified designed and coded.

• Components must be designed to a common standard e.g. – A component’s behaviour is described by its

specification.– A specification can have many implementations e.g.

to work on many platforms.

Example: Airline Booking System

• In airline systems there is often a mix of systems, including older systems and other different systems trying to do the same things.

• Systems need to be designed to enable the upgrading of older systems with minimum fuss and to enable the use of different types of booking process.

• A Bookings component provides an interface called makebooking which is available to any system who knows how to use it i.e. knows the services provided and their protocols or signatures

What are class stereotypes and why are they useful?

What are the advantages of this way of partitioning a system using entity, boundary and control class stereotypes?

1. Entity Classes

• -used to model data and behaviour of some real life system concept or entity e.g. member, bank account, order, employee.

• These will sometimes require more persistent storage of information e.g. a student’s details are ultimately stored as a student record.

• Represent the more permanent aspects of an application so class descriptions are less likely to chage e.g. members will always be added, updated and removed from a membership system.

2. Boundary (interface) Classes

• - model the interaction and manage communication between the computer system and its users. but don’t directly represent the specific interface object

• used to identify the main logical interfaces with users and other systems (including e.g. other software packages, printers).

• main task is to translate information across system boundaries

• partition the system so that interface is kept separate from business logic

These will end up as describing screens, reports, HTML pages, or other system interfaces that actors interact with.

3.Control Class

• glue between boundary elements and entity elements, describing the logic required to manage the various elements and their interactions

• Represent coordination, sequencing, transactions and control of other objects

• Represents the calculation and scheduling aspects if the logic of the use case i.e those bits of functionality that are not specific to the entity class but are specific to the use case.

Why are they useful?• Stereotyping boundary classes means that the

system is partitioned so that any changes to the interface or communication part are localised there.

• Stereotyping entity classes provide a model of the more permanent aspects of the application domain

• The control classes represent the calculation and scheduling aspects of the logic of the use case. If the functionality required changes, then the change can be localised.

Packages and Dependencies

• We can use this to organise classes into packages in such a way that change is localised.

• Minimise dependencies between these packages

• ensures the system remains robust in the face of changing requirements.

Example Agate (p246)• Packages mark out related but distinct

application areas: advert preparation, staff management, campaign management.

campaign managemen

tControl

staff management

advert preparation

User Interface

Software Design-related Topics

• What are the key characteristics of a quality software design and how can they be achieved?

• What is meant by coupling and cohesion and how can addressing these concepts help improve the quality of a software design? How can these principles be applied in the detailed design of a system?

• Explain how a layered approach to software design can make software more portable, flexible and extensible.