設計思維點滴一:complex system

The Five Attributes of a Complex System

 

Hierarchic Structure

Frequently, complexity takes the form of a hierarchy, whereby a complex system
is composed of interrelated subsystems that have in turn their own subsystems,
and so on, until some lowest level of elementary components is reached.

 

the fact that many complex systems have a nearly decomposable,
hierarchic structure is a major facilitating factor enabling us to understand,
describe, and even ‘see’ such systems and their parts.

 

The architecture of a complex system is a function of its components as well
as the hierarchic relationships among these components.

 

It is important to realize that the architecture of a complex system is a function of
its components as well as the hierarchic relationships among these components.
“All systems have subsystems and all systems are parts of larger systems. . . . The
value added by a system must come from the relationships between the parts, not
from the parts per se"

Relative Primitives原型

The choice of what components in a system are primitive is relatively arbitrary
and is largely up to the discretion of the observer of the system.
What is primitive for one observer may be at a much higher level of abstraction
for another.

Separation of Concerns

Intracomponent linkages are generally stronger than intercomponent linkages.
This fact has the effect of separating the high-frequency dynamics of the components—
involving the internal structure of the components—from the lowfrequency
dynamics—involving interaction among components.

This difference between intra- and intercomponent interactions provides a clear
separation of concerns among the various parts of a system, making it possible to
study each part in relative isolation.

Common Patterns

many complex systems are implemented with an economy
of expression.

 

Hierarchic systems are usually composed of only a few different kinds of subsystems
in various combinations and arrangements.

 

In other words, complex systems have common patterns. These patterns may
involve the reuse of small components, such as the cells found in both plants and
animals, or of larger structures, such as vascular systems, also found in both
plants and animals.

Stable Intermediate Forms過渡形式

“complex systems will evolve from simple systems much more rapidly if there
are stable intermediate forms than if there are not

 

A complex system that works is invariably found to have evolved from a simple
system that worked. . . . A complex system designed from scratch never works
and cannot be patched up to make it work. You have to start over, beginning with
a working simple system.

 

As systems evolve, objects that were once considered complex become the primitive
objects on which more complex systems are built. Furthermore, we can never
craft these primitive objects correctly the first time: We must use them in context
first and then improve them over time as we learn more about the real behavior of
the system.

Algorithmic versus Object-Oriented Decomposition

Although both designs solve the same problem, they do so in quite different ways.
In this second decomposition, we view the world as a set of autonomous agents
that collaborate to perform some higher-level behavior.

In this manner, each object in our solution embodies its own
unique behavior, and each one models some object in the real world. From this
perspective, an object is simply a tangible entity that exhibits some well-defined
behavior. Objects do things, and we ask them to perform what they do by sending
them messages. Because our decomposition is based on objects and not algorithms,
we call this an object-oriented decomposition.


Which is the right way to decompose a complex system—by algorithms or by
objects? Actually, this is a trick question because the right answer is that both
views are important: The algorithmic view highlights the ordering of events, and
the object-oriented view emphasizes the agents that either cause action or are the
subjects on which these operations act
.

 

 

■ Top-down structured design

Nevertheless, structured design
does not address the issues of data abstraction and information hiding, nor
does it provide an adequate means of dealing with concurrency. Structured
design does not scale up well for extremely complex systems, and this method
is largely inappropriate for use with object-based and object-oriented programming
languages.


■ Data-driven design

In this method, mapping system inputs to outputs
derives the structure of a software system. As with structured design,
data-driven design has been successfully applied to a number of complex
domains, particularly information management systems, which involve direct
relationships between the inputs and outputs of the system but require little
concern for time-critical events.


■ Object-oriented design

The underlying concept of object-oriented analysis is that one should
model software systems as collections of cooperating objects, treating individual
objects as instances of a class within a hierarchy of classes. Objectoriented
analysis and design directly reflects the topology of high-order
programming languages such as Smalltalk, Object Pascal, C++, the Common
Lisp Object System (CLOS), Ada, Eiffel, Python, Visual C#, and Java.

 

object-oriented decomposition has a number of
highly significant advantages over algorithmic decomposition. Object-oriented
decomposition yields smaller systems through the reuse of common mechanisms,
thus providing an important economy of expression. Object-oriented systems are
also more resilient to change and thus better able to evolve over time because
their design is based on stable intermediate forms. Indeed, object-oriented decomposition
greatly reduces the risk of building complex software systems because
they are designed to evolve incrementally from smaller systems in which we
already have confidence. Furthermore, object-oriented decomposition directly
addresses the inherent complexity of software by helping us make intelligent
decisions regarding the separation of concerns in a large state space.

 

 

The Role of Abstraction

 

anindividual can comprehend only about seven, plus or minus two, chunks of information
at one time. This number appears to be independent of information content.
As Miller himself observes, “The span of absolute judgment and the span of
immediate memory impose severe limitations on the amount of information that
we are able to receive, process and remember. By organizing the stimulus input
simultaneously into several dimensions and successively into a sequence of
chunks, we manage to break . . . this informational bottleneck”.In contemporary
terms, we call this process chunking or abstraction.

 

We are still constrained by the number of things that we can comprehendat one time,

but through abstraction, we use chunks of information with increasingly
greater semantic content. This is especially true if we take an object-oriented
view of the world because objects, as abstractions of entities in the real world,
represent a particularly dense and cohesive clustering of information.

 

抽象針對對象的本質行爲,劃分爲

靜態視圖:契約

動態視圖:協議

 

the principles on which object-oriented development is founded, namely,

abstraction, encapsulation, modularity, hierarchy,typing, concurrency, and persistence.

 

“abstraction arises from a recognition of similarities between certain objects, situations,

or processes in the real world, and the decision to concentrate upon these similarities

 and to ignore for the time being the differences”

 An abstraction denotes the essential characteristics of an object that distinguish it
from all other kinds of objects and thus provide crisply defined conceptual
boundaries, relative to the perspective of the viewer.

 

An abstraction focuses on the outside view of an object and so serves to separate
an object’s essential behavior from its implementation

 

the contract model of programming

the outside view of each object defines a contract on which other objects may depend,
and which in turn must be carried out by the inside view of the object itself (often
in collaboration with other objects).

contract encompasses the responsibilities of an object, namely, the
behavior for which it is held accountable.

A protocol denotes the ways in
which an object may act and react and thus constitutes the entire
static and
dynamic outside view of the abstraction.

What operations we can meaningfully perform on an object and how that
object reacts constitute the entire behavior of the object.

 

The Meaning of Encapsulation

Encapsulation hides the details of the implementation of an object

 封裝隱藏對象實現細節,致力於實現

Encapsulation is the process of compartmentalizing the elements of an abstraction
that constitute its structure and behavior; encapsulation serves to separate the
contractual interface of an abstraction and its implementation.

 

The Meaning of Modularity

Modularity is the property of a system that has been decomposed into a set of
cohesive and loosely coupled modules.

爲了降低軟件修復成本,每個模塊單元符合結構簡單,可獨立修改內部實現。

The overall goal of the decomposition into modules is the reduction of software cost by allowing modules
to be designed and revised independently. . . . Each module’s structure should
be simple enough that it can be understood fully; it should be possible to change
the implementation of other modules without knowledge of the implementation
of other modules and without affecting the behavior of other modules; the
ease of making a change in the design should bear a reasonable relationship to the
likelihood of the change being needed.

 

Finding the right classes and objects and then organizing them
into separate modules are largely independent design decisions. The identification
of classes and objects is part of the logical design of the system, but the identification
of modules is part of the system’s physical design. One cannot make all the
logical design decisions before making all the physical ones, or vice versa; rather,
these design decisions happen iteratively.

 

Data abstraction attempts to provide an opaque barrier behind which
methods and state are hidden; inheritance requires opening this interface to some
extent and may allow state as well as methods to be accessed without abstraction”
. For a given class, there are usually two kinds of clients: objects that invoke
operations on instances of the class and subclasses that inherit from the class.

 繼承違背封裝的三種變現形式

with inheritance, encapsulation can be violated in one
of three ways: “The subclass might access an instance variable of its superclass,
call a private operation of its superclass, or refer directly to superclasses of its
superclass” .Different programming languages trade off support for encapsulation
and inheritance in different ways. C++ and Java offer great flexibility.
Specifically, the interface of a class may have three parts: private parts, which
declare members that are accessible only to the class itself; protected parts, which
declare members that are accessible only to the class and its subclasses; and public
parts, which are accessible to all clients.

Examples of Hierarchy: Aggregation

 

Whereas these “is a” hierarchies denote generalization/specialization relationships,
“part of” hierarchies describe aggregation relationships.

 

Aggregation permits the physical grouping of logically
related structures, and inheritance allows these common groups to be easily
reused among different abstractions.

繼承是" is a ",高層抽象是一般化; 聚合是" part of ",高層抽象實現由低層抽象組成。

When dealing with hierarchies such as these, we often speak of levels of abstraction,

In terms of its “is a” hierarchy, a high-level abstraction is generalized, and a low-level abstraction is specialized.

Therefore, we say that a Flower class is at a higher level of abstraction than a Plant class.

In terms of its “part of” hierarchy, a class is at a higher level of
abstraction than any of the classes that make up its implementation. Thus, the class
Garden is at a higher level of abstraction than the type Plant, on which it builds.

 

Aggregation raises the issue of ownership.植物 花園  花園種植計劃 生命週期的管理

Our abstraction of a garden permits
different plants to be raised in a garden over time, but replacing a plant does not
change the identity of the garden as a whole, nor does removing a garden necessarily
destroy all of its plants (they are likely just transplanted). In other words,
the lifetime of a garden and its plants are independent. In contrast, we have
decided that a GrowingPlan object is intrinsically associated with a Garden
object and does not exist independently. Therefore, when we create an instance of
Garden, we also create an instance of GrowingPlan; when we

 

The Meaning of Typing

Typing is the enforcement of the class of an object, such that objects of different
types may not be interchanged, or at the most, they may be interchanged only in
very restricted ways.

It is sufficient to say that a class implements a type.

 

Strong typing prevents mixing of abstractions

 

there are a number of important benefits to be derived from using strongly typed languages:
■ Without type checking, a program in most languages can ‘crash’ in mysterious
ways at runtime.
■ In most systems, the edit-compile-debug cycle is so tedious that early error
detection is indispensable.
■ Type declarations help to document programs.
■ Most compilers can generate more efficient object code if types are declared

 

Examples of Typing: Static and Dynamic Typing

Strong and weak typing refers to type consistency, whereas
static and dynamic typing refers to the time when names are bound to types.

C++ java python強類型語言:即要求變量使用前需強制類型定義,所有變量都必須先定義後使用,

如果不經過強制類型轉換,類型保持不變。

弱類型語言:數據類型可以忽略,一個變量可以賦多個數據類型的值。

Static typing (also known as static binding or early binding) means that the types of all
variables and expressions are fixed at the time of compilation; dynamic typing
(also known as late binding) means that the types of all variables and expressions
are not known until runtime.

 

The opposite of polymorphism is monomorphism, which is found in all languages that
are both strongly and statically typed.

 

The Meaning of Concurrency

Concurrency is the property that distinguishes an active object from one that is
not active.

兩個或兩個以上的進程爲了影響其他進程中的變化而繼續改變自己的狀態但不做有用的工作,這樣的情形叫做活鎖。

互斥體實現了“mutual exclusion"互相排斥同步的簡單形式。

Building a large piece of software is hard enough; designing one that encompasses
multiple threads of control is much harder because one must worry about
such issues as deadlock, livelock, starvation, mutual exclusion, and race conditions.
“At the highest levels of abstraction, OOP can alleviate the concurrency
problem for the majority of programmers by hiding the concurrency inside reusable
abstractions


Examples of Concurrency

In general, there are three approaches to concurrency in object-oriented design.

First, concurrency is an intrinsic feature of certain programming languages,
which provide mechanisms for concurrency and synchronization. In this case, we

may create an active object that runs some process concurrently with all other active objects.

 

Second, we may use a class library that implements some form of lightweight
processes. Naturally, the implementation of this kind is highly platform-dependent,
although the interface to the library may be relatively portable.

 

Third, we may use interrupts to give us the illusion of concurrency. Of course, this
requires that we have knowledge of certain low-level hardware details. For example,
in our implementation of the class ActiveTemperatureSensor, we
might have a hardware timer that periodically interrupts the application, during
which time all such sensors read the current temperature and then invoke their
callback function as necessary.

 

The Meaning of Persistence

Persistence is the property of an object through which its existence transcends
time (i.e., the object continues to exist after its creator ceases to exist) and/or
space (i.e., the object’s location moves from the address space in which it was
created).

 

Persistence saves the state and class of an object across time or space

 

This spectrum of object persistence encompasses the following:
■ Transient results in expression evaluation
■ Local variables in procedure activations
■ Own variables, global variables, and heap items whose
extent is different from their scope
■ Data that exists between executions of a program
■ Data that exists between various versions of a program
■ Data that outlives the program

 

Unifying the concepts of concurrency and objects gives rise to concurrent object-oriented
programming languages. In a similar fashion, introducing the concept of
persistence to the object model gives rise to object-oriented databases. In practice,
such databases build on proven technology, such as sequential, indexed, hierarchical,
network, or relational database models, but then offer to the programmer the
abstraction of an object-oriented interface, through which database queries and
other operations are completed in terms of objects whose lifetimes transcend the
lifetime of an individual program. This unification vastly simplifies the development
of certain kinds of applications. In particular, it allows us to apply the same
design methods to the database and nondatabase segments of an application. 

 

 Summary


■ The maturation of software engineering has led to the development of
object-oriented analysis, design, and programming methods, all of which
address the issues of programming-in-the-large.
■ There are several different programming paradigms: procedure-oriented,
object-oriented, logic-oriented, rule-oriented, and constraint-oriented.
■ An abstraction denotes the essential characteristics of an object that distinguish
it from all other kinds of objects and thus provide crisply defined conceptual
boundaries, relative to the perspective of the viewer.
■ Encapsulation is the process of compartmentalizing the elements of an
abstraction that constitute its structure and behavior; encapsulation serves to
separate the contractual interface of an abstraction and its implementation.
■ Modularity is the property of a system that has been decomposed into a set
of cohesive and loosely coupled modules.
■ Hierarchy is a ranking or ordering of abstractions.
■ Typing is the enforcement of the class of an object, such that objects of different
types may not be interchanged or, at the most, may be interchanged
only in very restricted ways.

■ Concurrency is the property that distinguishes an active object from one that
is not active.
■ Persistence is the property of an object through which its existence transcends
time and/or space.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章