CSC/ECE 517 Fall 2007/wiki3 7 cl: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 10: Line 10:
===Principle of Small Interfaces ===
===Principle of Small Interfaces ===
The principle of small interfaces, also known as weak coupling, states that if any two modules communicate at all, they should exchange as
The principle of small interfaces, also known as weak coupling, states that if any two modules communicate at all, they should exchange as
little information as possible. The principle of small interfaces is supported by Java, and Eiffel. It is not difficult to follow this principle  in any o-o languages.
little information as possible. The principle of small interfaces is supported by Java, C++ and Eiffel. It is not difficult to follow this principle  in any o-o languages.


====Example of Principle of Small Interfaces ====
====Example of Principle of Small Interfaces ====
Line 23: Line 23:
===Principle of Explicit Interfaces ===
===Principle of Explicit Interfaces ===
The principle of explicit interfaces states that whenever two modules A and B communicate, this must be
The principle of explicit interfaces states that whenever two modules A and B communicate, this must be
obvious from the text of A or B or both. The principle of explicit interfaces is supported by Java, and Eiffel. It is not difficult to follow this principle  in any o-o languages.
obvious from the text of A or B or both. The principle of explicit interfaces is supported by Java, C++ and Eiffel. It is not difficult to follow this principle  in any o-o languages.


====Example of Principle of Explicit Interfaces ====
====Example of Principle of Explicit Interfaces ====
Line 29: Line 29:


===Uniform-access Principle ===
===Uniform-access Principle ===
The uniform-access principle states that all services offered by a module should be available through a uniform notation, which does not betray whether they are implemented through storage or through computation. The uniform-access principle is supported by Java, and Eiffel. It is not difficult to follow this principle in any o-o languages.
The uniform-access principle states that all services offered by a module should be available through a uniform notation, which does not betray whether they are implemented through storage or through computation. The uniform-access principle is supported by Java, Python Ruby and Eiffel. It is not difficult to follow this principle in any o-o languages.


====Example of Uniform-access Principle ====
====Example of Uniform-access Principle ====
Line 55: Line 55:


===Self-documentation Principle ===
===Self-documentation Principle ===
The designer of a module should strive to make all information about the module part of the module itself. Modules contain canonical minimal and complete documentation on their use. The self-documentation principle is supported by Java, and Eiffel. It is not difficult to follow this principle in any o-o languages.
The designer of a module should strive to make all information about the module part of the module itself. Modules contain canonical minimal and complete documentation on their use. The self-documentation principle is supported by Eiffel. It is difficult to follow this principle in other o-o languages.


====Example of Self-documentation Principle ====
====Example of Self-documentation Principle ====
Line 76: Line 76:


===Single-choice Principle ===
===Single-choice Principle ===
The single-choice principle states that whenever a software system must support a set of alternatives, one and only one module in the system should know their exhaustive list. The single-choice principle is supported by Java, and Eiffel. It is not difficult to follow this principle in any o-o languages.
The single-choice principle states that whenever a software system must support a set of alternatives, one and only one module in the system should know their exhaustive list. The single-choice principle is supported by Java, Ruby and Eiffel. It is not difficult to follow this principle in any o-o languages.


====Examples of Single-choice Principle ====
====Examples of Single-choice Principle ====

Latest revision as of 04:15, 30 November 2007

Bertrand Meyer is a prominent author in o-o design. He has developed a set of principles, many of which are embodied in the Eiffel language. Consider the principles of small interfaces, explicit interfaces, the uniform-access principle, the self-documentation principle, and the single-choice principle. What are good examples of each? Do other languages besides Eiffel support them? Is it difficult to follow these principles in certain o-o languages?


Bertrand Meyer's Set of Principles

Bertrand Meyer is the developer of the Eiffel programming language. As a developer, Dr. Meyer participates in the evolution of the Eiffel method and language which includes a set of principles that he developed. Some of the more important principles are the principle of small interfaces, explicit interfaces, the uniform-access principle, the self-documentation principle, and the single-choice principle.

Principle of Small Interfaces

The principle of small interfaces, also known as weak coupling, states that if any two modules communicate at all, they should exchange as little information as possible. The principle of small interfaces is supported by Java, C++ and Eiffel. It is not difficult to follow this principle in any o-o languages.

Example of Principle of Small Interfaces

An ATM Example uses a Message class to encapsulate details of a Message from a Transaction to the bank. This is used as a parameter to the sendMessage() method of NetworkToBank - in place of a long list of specific parameters. This means that only the sending Transaction and receiving bank need to be aware of the details of the structure of a message - not the intermediate class(es) comprising the network.

Principle of Explicit Interfaces

The principle of explicit interfaces states that whenever two modules A and B communicate, this must be obvious from the text of A or B or both. The principle of explicit interfaces is supported by Java, C++ and Eiffel. It is not difficult to follow this principle in any o-o languages.

Example of Principle of Explicit Interfaces

Uniform-access Principle

The uniform-access principle states that all services offered by a module should be available through a uniform notation, which does not betray whether they are implemented through storage or through computation. The uniform-access principle is supported by Java, Python Ruby and Eiffel. It is not difficult to follow this principle in any o-o languages.

Example of Uniform-access Principle

Ruby Programming language:

class Foo
 attr_reader :x
 def initialize(x)
   @x = x
 end
 def x_times_5
   return @x*5
 end
end
y = Foo.new(2)
puts y.x
puts y.x_times_5

This code outputs:

2
10

Note: Even though x is an attribute and x_times_5 is a parameterless method call, they're accessed the same way.

Self-documentation Principle

The designer of a module should strive to make all information about the module part of the module itself. Modules contain canonical minimal and complete documentation on their use. The self-documentation principle is supported by Eiffel. It is difficult to follow this principle in other o-o languages.

Example of Self-documentation Principle

Eiffel provides superior support for this through:

Indexing Clauses

Class text begins with an indexing clause that contains a standardized but extensible set of tagged (searchable) lines describing various aspects of the class:

indexing
  description:
       "Dispensers that provide access to only one item at a time."
   status: "Todd Plessel, plessel@vislab.epa.gov"
   names: "dispenser"
   representation: "none"
   access: "fixed", "membership"
   contents: "generic"
   date: "$Date: 1998/02/22 17:00:00 $"
   revision: "$Revision: 1.0 $"

Single-choice Principle

The single-choice principle states that whenever a software system must support a set of alternatives, one and only one module in the system should know their exhaustive list. The single-choice principle is supported by Java, Ruby and Eiffel. It is not difficult to follow this principle in any o-o languages.

Examples of Single-choice Principle

Example 1 - Editor: set of commands (insert, delete etc.)
Example 2 - Graphics system: set of figure types (rectangle, circle etc.)
Example 3 - Compiler: set of language constructs (instruction, loop, expression etc.)

Resources

Bertrand Meyer Wiki
List of Principles
Uniform-Access Principle
Single-Choice Principle
Design Quality
Software Architecture
Why Eiffel