Software Architecture : Software Architecture
Instructor:
Yushan (Michael) Sun
Fall 2004
About Test (关于考试) : About Test (关于考试) 30% project, architecture design
10% coding, use Java to write a program
60% testing, closed book test
Slide3 : 软件开发成本分布图 软件体系结构序言
Slide4 : the position of software architecture 软件体系结构序言
Short History of SA (软件体系结构简史) : Short History of SA (软件体系结构简史) In 1990’s, the term software architecture began to gain widespread acceptance both in industry and the research community.
The field software architecture was created out of necessity.
In 1990’s, Software systems were growing larger: systems of hundreds of thousands or even millions of lines of code were becoming commonplace.
软件体系结构序言
Short History of SA (软件体系结构简史) : Three reasons why SA is important to large,
complex, software-intensive systems.
它是一种传达手段. It is a vehicle for communication among stakeholders.
Software architecture represents a common
abstraction of a system that most of the system's stakeholders can use as a basis to communicate with each other.
Stakeholder: 赌金保管人, 股东,各方利益者 Short History of SA (软件体系结构简史) 软件体系结构序言
Slide7 : 2. 它是最早的设计决策的代表. It is the representation of the earliest design decisions. The SA of a system
is the earliest artifact that enables the priorities to be analyzed, and
is the artifact (人造物品) that has the most significant influence on system qualities.
It shows the tradeoffs (折衷)
between performance and security,
between maintainability and reliability, and
between the cost of the current development effort and the cost of future developments in the architecture. Short History of SA 软件体系结构序言
Slide8 : 3. It is a reusable, transferable abstraction of a system. (一个系统的可重复利用的,可转移的抽象)
Software architecture constitutes (组成)
a relatively small,
intellectually graspable (智力上能理解的)
model for how a system is structured and how its components work together.
This model is transferable (可转移的) across systems; it
can be applied to other systems exhibiting similar requirements and (用到其它的项目)
can promote large-scale reuse and software product lines (提高大规模重复利用率)
Short History of SA 软件体系结构序言
Slide9 : 例如: 三层结构. A 3-tire client-server architecture, a reusable common framework for many applications Short History of SA 软件体系结构序言 Web application program
student credit
management
system
salary
management
system
Lecture 1. Call-and-return with Object Oriented Systems : Lecture 1. Call-and-return with Object Oriented Systems Main Program and Subroutine
Object Oriented Systems
Case studies:
1. KWIC: OO Architectural Style
2. Instrumentation Software OO Design
Failed
3. CRUISE CONTROL-OO Architecture
Slide11 : Figure 2.1 a list of common architectural styles
Slide12 : 1. Main Program and Subroutine
Slide13 : Evolution of Program Design
Unstructured programming : Unstructured programming All the program code written in a single continuous main program. Many disadvantages for large
programs
difficult to follow logic
if something needs to be done more than once must be re-typed
hard to incorporate other code
not easily modified
difficult to test particular portions of the code
...
Top-down functional design (自上而下的功能设计) : Top-down functional design (自上而下的功能设计) 1. Main Program and Subroutine
Slide16 : 从功能的观点设计系统The system is designed from a functional viewpoint, starting with a high-level view and progressively refining this into a more detailed design.
This methodology is exemplified by Structured Design and step-wise refinement (结构化设计与逐步细化是这种方法的一个例子). 1. Main Program and Subroutine
Slide17 : Advantage (优点)
成功的设计方法,可以被用于较大程序. This has proved to be a highly successful
design methodology. It has allowed the
development of large programs (100,000 lines or more of source code). 1. Main Program and Subroutine
Slide18 : Disadvantage (缺点):
程序超过10万行,表现不好. However, as program size increases beyond this point (100,000 lines), the approach performs poorly.
程序太大,开发太慢, 测试越来越困难. We observe that code development becomes too slow and that it becomes increasingly difficult to test the software and guarantee its reliability. 1. Main Program and Subroutine
2. Object-oriented design : 2. Object-oriented design The system is viewed as a collection of objects rather than as functions with messages passed from object to object.
Each object has its own set of associated operations.
Object-oriented design is based on the idea of information hiding which was first put forward by Parnas (1972) and is very popular now.
Slide20 : 2. Object-oriented design
什么叫对象? What is an Object? : 什么叫对象? What is an Object? floats, ints, chars - all are primitive objects in C++ (and in C).
OOD/OOP extends this idea to ``higher-level'' objects, things like strings, stacks, queues, etc.
An Object is something with a:
状态. State (i.e., it holds Data), and a;
语义. Semantics (i.e., rules for changing its state). 2. Object-oriented design
Slide22 : 程序员定义对象. Note that it is the Programmer who defines these objects and the operations allowed on them.
这是最简单的面向对象设计的方面. This is the simplest aspect of object-oriented design --- the specification, use and re-use of Abstract Data Types (ADTs). 2. Object-oriented design
Example: animal family - OOD : Example: animal family - OOD Requirement specifications:
Write a program to tell a story happened in an animal family that includes a tiger, a dog and a
cat.
When the tiger sees the dog, he will chase it. Tigers can see, and laugh.
When the dog sees the cat he will chase it. Dogs can chase, run and bark.
when the cat sees the tiger or the dog he will escape and climb up to a tree. Cats can laugh, climb, mew, and escape. 2. Object-oriented design
Slide25 : How to do object oriented design? 确认对象. Identify objects
名词. typically nouns in problem statement
here, program, story, animal family, tiger, dog, cat
祛除同义词. Discard synonyms
适当聚集以便产生合适的关键的类. Aggregate as appropriate to determine key classes
一些动词将成为函数. Some verbs will become functions
Here: sees, chase, laugh, run, bark, escape, new 2. Object-oriented design
Slide26 : 2. Object-oriented design
Slide27 : Tiger BigTiger = new Tiger();
Dog YoungDog=new Dog();
Cat CleverCat= new Cat();
BigTiger.see(YoungDog);
BigTiger.chase(YoungDog);
youngDog.run();
BigTiger.sees(CleverCat);
BigTiger.chase(CleverCat);
CleverCat.mew();
CleverCat.escape();
CleverCat.climbTree();
BigTiger.laugh(); 2. Object-oriented design
Slide28 : 对象结构. Object architectures
封装. Encapsulation
Restrict access to certain information
遗传. Inheritance
Share one definition of shared functionality
动态绑定. Dynamic binding
Determine actual operation to call at runtime
多对象管理. Management of many objects
Provide structure on large set of definitions
重复利用. Reuse and maintenance
Exploit capsulation and locality 2. Object-oriented design
Alternative views : Alternative views 隐藏信息. Hide information
Parnas’ view: encapsulation based on hiding of design “secrets”
隐藏表示. Hide data representation
ADT view: enforce boundaries of abstraction by hiding data representation
Maintain integrity of data representation
模拟现实世界. Model the real world
Program with nouns not verbs
Entities defined by actions it suffers and requires 2. Object-oriented design
Slide30 : Notes on objects in OO architecture:
The components of this style are the objects (instances of abstract data types). Objects are examples of a type of component.
we call a component of OO architecture a manager because it is responsible for preserving the integrity of a resource (here
the representation). 2. Object-oriented design
Slide31 : 对象通过函数或者过程调用交互.
Objects interact through function and procedure invocations. Two important aspects of this style are
1) that an object is responsible for preserving the integrity of its representation (usually by
maintaining some invariant over it), and
2) that the representation is hidden from other
objects. Figure 2.3 illustrates this style.4 2. Object-oriented design
OOD 的特点. Characteristics of OOD : OOD 的特点. Characteristics of OOD 对象是对现实世界的抽象.Objects are abstractions of real-world or system entities and manage themselves
对象是相互独立的. Objects are independent
系统功能用对象服务表达. System functionality is expressed in terms of object services
无共享数据区. Shared data areas are eliminated
对象可以是分布的. Objects may be distributed
对象可以被顺序或平行执行. Objects may execute sequentially or in parallel 2. Object-oriented design
OOD 的优点. Advantages of OOD : OOD 的优点. Advantages of OOD 容易维护. Easier maintenance. Because an object hides its representation from its clients, it is possible to change the implementation without affecting those clients Objects may be understood as stand-alone entities
重复利用. Reusable: Objects are appropriate reusable components
反映现实世界. Real world mapping: For some systems, there may be an obvious mapping from real world entities to system objects
容易解刨分一个系统. Easy decomposition of a system: the bundling of a set of accessing routines with the data they manipulate allows designers to decompose problems into collections of interacting agents. 2. Object-oriented design
Disadvantage of OOD : : Disadvantage of OOD : 必须知道对象的身份. In order for one object to interact with another (via procedure call) it must know the identity of that object.
Comparison: in pipe-and-filter systems, filters do not need to know what other filters are in the system in order to interact with them. 2. Object-oriented design
A generalisation hierarchy : A generalisation hierarchy super-class Sub-class 2. Object-oriented design
Class Generalisation and Inheritance : Class Generalisation and Inheritance A sub-class inherits the attributes and operations from its super class and may add new methods or attributes of its own
It is a reuse mechanism at both the design and the programming level
Inheritance introduces complexity and this is undesirable, especially in critical systems 2. Object-oriented design
Slide37 : Inheritance in C++ and Java 2. Object-oriented design
3. Case studies : 3. Case studies
Slide39 : Case study 1. Key Words in Context
In this paper of 1974, Parnas proposed the
following problem: KWIC (key words in
Context ) index system, [Par72j]:
Accepts an ordered set of lines;
Each Line is an ordered set of words,
Each word is an ordered set of characters.
Any line Maybe circularly shifted by repeatedly removing the first word and appending it at the end of the line.
The KWIC index system outputs a listing of all circular shifts of all lines in alphabetical order. 3. Case studies
Slide40 : 3. Case studies
Main Program/Subroutine With Shared Data : Main Program/Subroutine With Shared Data This solution decomposes the problem according to the four basic functions performed:
input, shift, alphabetize, output.
These computational components are coordinated as subroutines by a main program that sequences through them in turn.
Data is communicated between the components through shared storage ("core storage"). (see Figure 3.1). 3. Case studies
Slide42 : Figure 3.1. KWIC: Shared Data Solution Kwic: Main program-subroutine architecture 3. Case studies Run Program
KWIC: OO Architecture : KWIC: OO Architecture Architecture: The solution with object-oriented
Architectural style decomposes the system into
six modules:
Master control module, responsible for controling the sequence of method invokations in other modules.
LineStorage module, responsible for holding all characters from all words and lines. 3. Case studies
Slide44 : Input module, responsible for reading the data from a file and storing it in LineStorage module.
CircularShifter module, responsible for producing circular shifts of lines stored in LineStorage module.
Alphabetizer module, responsible for sorting circular shifts alphabetically.
Output module, responsible for prinitng the sorted shifts. 3. Case studies
Slide45 : 3. Case studies KWIC: OO Architecture Run Program
Slide46 : In the object-oriented solution the data is not shared between the computational components.
Each module provides an interface that permits other components to access data only by invoking methods in that interface.
For example, LineStorage module provides the public interface that allows other modules to set character in a particular word in a particular line, read a specific character, read, set or delete a particular word in a specific line, read whole line at once, etc. 3. Case studies
Slide47 : Advantages of OOD structure of kwic:
algorithms can be changed in individual modules without affecting others
data representations can be changed in individual modules without affecting others.
Reuse is better supported than in the main/subroutine solution because modules make fewer assumptions about the others with which they interact. 3. Case studies
Slide48 :
The main problem is that to add new functions to the system, the implementer must either modify the existing modules—compromising their simplicity and integrity—or add new modules that lead to performance penalties. (See [GKN92] for a detailed
discussion.) Disadvantages of OOD structure of kwic : 3. Case studies
Slide49 : Case study 2. Instrumentation Software (仪器软件) OO Design Failed 3. Case studies
Slide50 : Objective: to show software design of An
oscilloscope (示波镜) in Tektronix, Inc to develop
a reusable system architecture for oscilloscopes
An oscilloscope (示波镜) is an instrumentation
system that samples electrical signals and displays pictures (called traces) of them on a screen.
Oscilloscopes also perform measurements on the signals, and display them on the screen. 3. Case studies
Slide51 : Modern oscilloscopes perform dozens of
measurements:
supply megabytes of internal storage,
support an interface to a network of
workstations and other instruments,
and provide a sophisticated user interface,
a touch-panel screen with menus,
built-in help facilities,
and color displays 3. Case studies
Slide52 : The object-oriented model clarified the data types used in oscilloscopes: waveforms, signals, measurements, trigger modes, and so on (see Figure 3.6)
However, it failed to produce the hoped-for results
Although many types of data were identified, there was no overall model that explained how the types fit together Solution: An Object Oriented Model 3. Case studies
Slide53 : Figure 3.6 Oscilloscope: an object-oriented model 3. Case studies
Slide54 : Case study 3: CRUISE CONTROL-OO Architecture A cruise-control system is a system used to maintain the speed of a car, even over varying terrain.
Figure 3.16 shows the block diagram of the hardware for such a system.
There are several inputs: 3. Case studies
Slide55 : 3. Case studies
Slide56 : FIGURE 3.16 Booch Block Diagram for Cruise Control 3. Case studies
Slide57 : OBJECT VIEW OF CRUISE CONTROL Booch organizes an object-oriented decomposition of the system around objects that exist in the task description.
The elements of the decomposition correspond to important quantities and physical entities in the system, as shown in Figure 3.17, where the blobs represent objects, and the directed lines represent
dependencies among objects. 3. Case studies
Slide58 : FIGURE 3.17 Booch's O-O Design for Cruise Control Depend on 3. Case studies