CSC/ECE 517 Fall 2009/wiki3 7 Single Choice Pattern am: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
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. It is one of the five principles of software construction as stated by Bertrand Meyer, the other four being the Linguistic Modular Units Principle, the Self- Documentation Principle, the Uniform- Access Principle, and the Open- Closed Principle. The Single Choice Principle may be viewed as a consequence of both the Open-Closed and information Hiding rules.
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. It is one of the five principles of software construction as stated by Bertrand Meyer, the other four being the Linguistic Modular Units Principle, the Self- Documentation Principle, the Uniform- Access Principle, and the Open- Closed Principle. The Single Choice Principle may be viewed as a consequence of both the Open-Closed and information Hiding rules.
===Violation of Single Choice Principle===
===Violation of Single Choice Principle===
Consider a  type used to manage a declared in Pascal-Ada syntax :
<pre>Type Publication=
record
author,title:STRING;
publication_year:INTEGER;
case pubtype: (book,journal,conference_proceedings)of
book: (publisher:STRING);
journal: (volume,issue:STRING);
proceedings: (editor, place:STRING) – Conference proceedings
end</pre>
Let B be a typical client of A. B will manipulate publications through a variable such as
p:PUBLICATION
and to do anything useful with p, will need to discriminate explicitly between the various cases, as in:
<pre> case p of
book:..Instructions which may access the field p.publisher
journal:..Instructions which may access fields p.volume,p.issue
proceedings:..Instructions which may access fields p.editor,p.place
end</pre>
Now, whenever there is a need for a new variant, say technical reports of companies in this case, there is a need to extend the definition of type PUBLICATION in module A to support the new case, as well as  any client of A, such as B, will also require updating if it is used as a structure such as above, relying on an explicit list of cases for p.
What is observed is a violation of the SCP and is a disastrous situation for software change and evolution as a simple and natural addition may cause a chain reaction of changes across many client changes. This violation will occur whenever a certain notion admits a number of variants for eg.,
• I

Revision as of 20:33, 17 November 2009

Single Choice Principle

Introduction

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. It is one of the five principles of software construction as stated by Bertrand Meyer, the other four being the Linguistic Modular Units Principle, the Self- Documentation Principle, the Uniform- Access Principle, and the Open- Closed Principle. The Single Choice Principle may be viewed as a consequence of both the Open-Closed and information Hiding rules.

Violation of Single Choice Principle

Consider a type used to manage a declared in Pascal-Ada syntax :

Type Publication=
	record
		author,title:STRING;
		publication_year:INTEGER;
	case 	 pubtype: (book,journal,conference_proceedings)of
		book: (publisher:STRING);
		journal: (volume,issue:STRING);
		proceedings: (editor, place:STRING) – Conference proceedings
	end

Let B be a typical client of A. B will manipulate publications through a variable such as p:PUBLICATION and to do anything useful with p, will need to discriminate explicitly between the various cases, as in:

	case p of 
		book:..Instructions which may access the field p.publisher
		journal:..Instructions which may access fields p.volume,p.issue
		proceedings:..Instructions which may access fields p.editor,p.place
	end

Now, whenever there is a need for a new variant, say technical reports of companies in this case, there is a need to extend the definition of type PUBLICATION in module A to support the new case, as well as any client of A, such as B, will also require updating if it is used as a structure such as above, relying on an explicit list of cases for p. What is observed is a violation of the SCP and is a disastrous situation for software change and evolution as a simple and natural addition may cause a chain reaction of changes across many client changes. This violation will occur whenever a certain notion admits a number of variants for eg., • I