<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Maverick</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Maverick"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Maverick"/>
	<updated>2026-05-23T13:23:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29798</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29798"/>
		<updated>2009-11-21T05:00:25Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Principle of Small Interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size and scope of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
This principle results in a large number of interfaces, but that is fine if it makes the code modular and loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by using an Interface, exposes methods to fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2) Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs the list of employees, then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29657</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29657"/>
		<updated>2009-11-19T04:36:11Z</updated>

		<summary type="html">&lt;p&gt;Maverick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size and scope of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
This principle results in a large number of interfaces, but that is fine if it makes the code modular and loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2) Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs the list of employees, then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29651</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29651"/>
		<updated>2009-11-19T04:33:58Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size and scope of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
This principle results in a large number of interfaces, but that is fine if it makes the code modular and loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2) Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs the list of employees, then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29649</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29649"/>
		<updated>2009-11-19T04:33:32Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size and scope of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
This principle results in a large number of interfaces, but that is fine if it makes the code modular and loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2) Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29646</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29646"/>
		<updated>2009-11-19T04:31:42Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Principle of Small Interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size and scope of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
This principle results in a large number of interfaces, but that is fine if it makes the code modular and loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29643</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29643"/>
		<updated>2009-11-19T04:30:09Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Interface Segregation Principle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size and scope of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
This principle results in a large number of interfaces, but that is fine if it makes the code modular and loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29639</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29639"/>
		<updated>2009-11-19T04:28:14Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size and scope of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29638</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29638"/>
		<updated>2009-11-19T04:27:41Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks (also known as Interfaces) with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29619</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29619"/>
		<updated>2009-11-19T04:18:57Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29614</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29614"/>
		<updated>2009-11-19T04:16:52Z</updated>

		<summary type="html">&lt;p&gt;Maverick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [[http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29606</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29606"/>
		<updated>2009-11-19T04:15:19Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI#Violation_of_Modular_Protection section 3.2]. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29604</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29604"/>
		<updated>2009-11-19T04:14:41Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Violation of Modular Continuity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (like [http://hadoop.apache.org/ Hadoop]), may not need this SQL Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29602</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29602"/>
		<updated>2009-11-19T04:14:08Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Violation of Modular Continuity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the &amp;lt;code&amp;gt;dbConnection&amp;lt;/code&amp;gt; of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like [http://hadoop.apache.org/ Hadoop]), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29596</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29596"/>
		<updated>2009-11-19T04:12:57Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Principle of Small Interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of ''Modular Protection'' and ''Modular Continuity''. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like [http://hadoop.apache.org/ Hadoop]), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29592</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29592"/>
		<updated>2009-11-19T04:12:33Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Clients Should not be forced to use Interface they don't use */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which &amp;lt;code&amp;gt;work()&amp;lt;/code&amp;gt; is used and during lunch break &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; is used. But if we try to implement a robot, then we are forced to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; on robot also though it is not using it. We are forcing robot to use &amp;lt;code&amp;gt;eat()&amp;lt;/code&amp;gt; which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like [http://hadoop.apache.org/ Hadoop]), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29587</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29587"/>
		<updated>2009-11-19T04:10:23Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like [http://hadoop.apache.org/ Hadoop]), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
1. [http://www.oodesign.com/interface-segregation-principle.html OODesign.com]&lt;br /&gt;
&lt;br /&gt;
2. [http://www.objectmentor.com/resources/articles/isp.pdf The Interface Segregation Principle on the ObjectMentor.com]&lt;br /&gt;
&lt;br /&gt;
3. [http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx David Hayden's blog]&lt;br /&gt;
&lt;br /&gt;
4. [http://www2.lib.ncsu.edu/catalog/record/NCSU960289 Object-Oriented Software Construction. by Meyer, Bertrand]&lt;br /&gt;
&lt;br /&gt;
4. [http://www.mihswat.com/2008/11/27/good-software-modularity-what-exactly-is-it/ &amp;quot;Good software modularity. What exactly is it?&amp;quot; by Otavio Ferreira]&lt;br /&gt;
&lt;br /&gt;
5. [http://userpages.umbc.edu/~khoo/survey2.html &amp;quot;A Survey of Major Software Design Methodologies&amp;quot;]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29580</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29580"/>
		<updated>2009-11-19T04:04:06Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Violation of Modular Continuity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like [http://hadoop.apache.org/ Hadoop]), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29579</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29579"/>
		<updated>2009-11-19T04:03:24Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29577</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29577"/>
		<updated>2009-11-19T04:02:14Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
\t By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
\t By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29575</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29575"/>
		<updated>2009-11-19T04:02:00Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
1) Interface Segregation Principle:&lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
2)Principle of Small Interfaces:&lt;br /&gt;
&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29574</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29574"/>
		<updated>2009-11-19T04:01:25Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Interface Segregation Principle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.).&lt;br /&gt;
&lt;br /&gt;
==Principle of Small Interfaces==&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29573</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29573"/>
		<updated>2009-11-19T04:00:57Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Compare and Conclude */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
At the outset it seems both the principles deal in recommend in using small interfaces by giving different guidelines. But a finer comparison can be made based on the code in section 3.2. &lt;br /&gt;
&lt;br /&gt;
== Interface Segregation Principle==&lt;br /&gt;
By applying the Interface Segregation Principle, the need for removal of the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; cannot be argued. The method can be used by the clients to make one Database request and save it with the client so that the lookup can be done without any further call (The flip side is though client may not have an updated list of employees, which in any case will not change frequently.). &lt;br /&gt;
&lt;br /&gt;
==Principle of Small Interfaces==&lt;br /&gt;
By applying Principle of Small Interfaces, we have already identified that the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; method is not required. If the client needs then there could be as many database calls as required and make its own list of required employees and not have redundant data.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29555</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29555"/>
		<updated>2009-11-19T03:53:32Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Interface Segregation Principle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The rational for the principle can argued by the following points.&lt;br /&gt;
&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29551</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29551"/>
		<updated>2009-11-19T03:52:43Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Interface Segregation Principle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
The principle states that:&lt;br /&gt;
 &amp;quot;The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.&amp;quot;&lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29545</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29545"/>
		<updated>2009-11-19T03:51:13Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Compare and Conclude=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29478</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29478"/>
		<updated>2009-11-19T03:18:17Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Violation of Modular Protection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt; will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
This is a violation of the principle of Modular Protection which could have been avoided by blocking the communication channel via the &amp;lt;code&amp;gt;getEmployeeMap&amp;lt;/code&amp;gt;, based on the Principle of Small Interfaces.&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29472</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29472"/>
		<updated>2009-11-19T03:16:07Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Violation of Modular Protection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this case the method getEmployeeMap will return the entire Hashmap of the employees where as all was required was a search operation based on some criteria. This exposes more data than is required by the clients and will allow them to access it and modify it case of [http://www.javaranch.com/journal/2003/04/immutable.htm mutable objects].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29462</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29462"/>
		<updated>2009-11-19T03:12:12Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Violation of Modular Protection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29460</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29460"/>
		<updated>2009-11-19T03:11:21Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Violation of Modular Protection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
 &lt;br /&gt;
    private Connection dbConnection;&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29459</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29459"/>
		<updated>2009-11-19T03:11:00Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Principle of Small Interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. &lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Continuity==&lt;br /&gt;
&lt;br /&gt;
Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
In this above code the ''dbConnection'' of the type ''java.sql.connection'' is needed but for the internal usage of the Service. There is no need for the clients to be aware of it, or implement the getter and setter methods. If say one is using [http://java.sun.com/docs/books/tutorial/jdbc/ JDBC], then the connection object makes sense, but if a business decided to use [http://en.wikipedia.org/wiki/Mainframe_computer Mainframes] or any other [http://stackoverflow.com/questions/677253/what-are-alternatives-to-sql-database-storage-for-a-web-site non SQL] databases (Like http://hadoop.apache.org/ Hadoop), may not need this Sql Connection object at all. &lt;br /&gt;
&lt;br /&gt;
This example is the called as violation of Modular Continuty, as the change in the business requirements has an impact of the client classes whereas if the Service was designed based on Principle of Small Interfaces, redundant communication channels could have been not developed, making the code resuable and more flexible.&lt;br /&gt;
&lt;br /&gt;
==Violation of Modular Protection==&lt;br /&gt;
&lt;br /&gt;
This violation is caused by giving access to common or more data than required by exposing methods by an interface. Consider the code snippet below.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
 &lt;br /&gt;
    private Connection dbConnection;&lt;br /&gt;
    private HashMap employeeMap;&lt;br /&gt;
 &lt;br /&gt;
    public HashMap getEmployeeMap() {&lt;br /&gt;
        return employeeMap;&lt;br /&gt;
    }&lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
        // implementation …&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void saveEmployee(Employee emp) {&lt;br /&gt;
        // implementation…&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29409</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29409"/>
		<updated>2009-11-19T02:46:56Z</updated>

		<summary type="html">&lt;p&gt;Maverick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Principle of Small Interfaces=&lt;br /&gt;
The principle states that:&lt;br /&gt;
&lt;br /&gt;
 “If two modules communicate, they should exchange as little information as possible”&lt;br /&gt;
&lt;br /&gt;
This principle is driven by the earlier mentioned rules of “Modular Protection” and “Modular Continuity”. If a system communicating with a client by an Interface exposes methods of fetch more information than needed, then there is chance of corruption of the common data that is not required by the system. Consider the following example which will illustrate the concept:&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate)&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation… &lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This class helps in looking up an employee of the company. This is a simple example which adheres to the principle of small interfaces. The business requirements are to provide two search methods based on employee ID and Last Name – Date of Birth. Consider the following code snippet which is another implementation of the similar business requirement.&lt;br /&gt;
&lt;br /&gt;
 public class EmployeeLookupService {&lt;br /&gt;
     private Connection dbConnection;&lt;br /&gt;
 &lt;br /&gt;
    public Connection getDbConnection() {&lt;br /&gt;
        return dbConnection;&lt;br /&gt;
    }&lt;br /&gt;
    public void setDbConnection(Connection newDBConnection) {&lt;br /&gt;
        dbConnection = newDBConnection;&lt;br /&gt;
    }&lt;br /&gt;
     public List getEmployeesForNameDOB(String lastName, Date birthDate) {&lt;br /&gt;
         // implementation …&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public Employee getEmployeeForID(int employeeId) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
         return null;&lt;br /&gt;
     }&lt;br /&gt;
     public void saveEmployee(Employee emp) {&lt;br /&gt;
         // implementation…&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29387</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=29387"/>
		<updated>2009-11-19T02:35:00Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
OO languages are inherently modular in structure. The functioning mechanism of the code is via the interaction of each of these modules or blocks with each other. The design of the modules is driven by the following restrictions imposed on them:&lt;br /&gt;
&lt;br /&gt;
1.'''Modular Decomposability''' – A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex sub-problems, connected by a simple structure, and independent enough to allow further work to proceed separately on each item.&lt;br /&gt;
&lt;br /&gt;
2.'''Modular Composability''' – A software construction method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed.&lt;br /&gt;
&lt;br /&gt;
3.'''Modular Understandability''' – A software construction method satisfies Modular Understandability if it helps produce software which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others.&lt;br /&gt;
&lt;br /&gt;
4.'''Modular Continuity''' – A software construction method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or a small number of modules.&lt;br /&gt;
&lt;br /&gt;
5.'''Modular Protection''' – A software construction method satisfies Modular Protection if it yields architectures in which the effect of an abnormal condition occurring at run time in a module will remain confined to that module, or at worst will only propagate to a few neighboring modules.&lt;br /&gt;
&lt;br /&gt;
Of these the last two talk about the size of the Interfaces. In this article we will try to cover and explain two principles that give developer a guideline on the size content of an Interface and the redundancy in the methods that one should avoid so that we get a loosely coupled architecture flexible in enough to work with minimal code change. &lt;br /&gt;
&lt;br /&gt;
Please refer the sections below.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
Consider an Interface shown below&lt;br /&gt;
 interface Iworker{&lt;br /&gt;
        public void work();&lt;br /&gt;
        public void eat();&lt;br /&gt;
                   }&lt;br /&gt;
&lt;br /&gt;
If we try to implement a class worker using above interface, the worker is allocated some time for working during which work() is used and during lunch break eat() is used. But if we try to implement a robot, then we are forced to use eat() on robot also though it is not using it. We are forcing robot to use eat() which is not being used.&lt;br /&gt;
&lt;br /&gt;
So we have to use different type of interface which doesn't force interfaces on clients which are not used. The following code explains it.&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Comparision of Aptana,Netbeans and Rubymine=&lt;br /&gt;
&lt;br /&gt;
Three IDEs namely Aptana's Radrails, Netbeans and Rubymine are compared in the following sections.&lt;br /&gt;
==System Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
==Features for Ruby==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other Features available in IDE's=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
http://www.oodesign.com/interface-segregation-principle.html&lt;br /&gt;
&lt;br /&gt;
http://www.objectmentor.com/resources/articles/isp.pdf&lt;br /&gt;
&lt;br /&gt;
http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27563</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27563"/>
		<updated>2009-11-17T20:18:52Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Interface Segregation Principle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
This page tries to review Integrated Development Environments for Ruby such as Aptana,Rubymine and Netbeans. Also the IDEs are compared with respect to certain dimensions such as facilities, ease of use, system requirements, and support for the Ruby way of thinking.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of a real system where the Interface-Segregation Principle is required to make the client usage simple. &lt;br /&gt;
&lt;br /&gt;
Consider a User interface for ATM machine with a UI that allows conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
The end goal is to have a seamless user experience for a user with a fast turnaround time. You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client. &lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Comparision of Aptana,Netbeans and Rubymine=&lt;br /&gt;
&lt;br /&gt;
Three IDEs namely Aptana's Radrails, Netbeans and Rubymine are compared in the following sections.&lt;br /&gt;
==System Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
==Features for Ruby==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other Features available in IDE's=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27560</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27560"/>
		<updated>2009-11-17T20:14:36Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Interface Segregation Principle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
This page tries to review Integrated Development Environments for Ruby such as Aptana,Rubymine and Netbeans. Also the IDEs are compared with respect to certain dimensions such as facilities, ease of use, system requirements, and support for the Ruby way of thinking.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of the Interface-Segregation Principle.  Consider a User interface for ATM machine, where it may logically stand to reason you may have separate interfaces for a person conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need and in turn cause confusion to the final client.&lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Comparision of Aptana,Netbeans and Rubymine=&lt;br /&gt;
&lt;br /&gt;
Three IDEs namely Aptana's Radrails, Netbeans and Rubymine are compared in the following sections.&lt;br /&gt;
==System Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
==Features for Ruby==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other Features available in IDE's=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27559</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27559"/>
		<updated>2009-11-17T20:13:51Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Interface Segregation Principle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
This page tries to review Integrated Development Environments for Ruby such as Aptana,Rubymine and Netbeans. Also the IDEs are compared with respect to certain dimensions such as facilities, ease of use, system requirements, and support for the Ruby way of thinking.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of the Interface-Segregation Principle.  Consider a User interface for ATM machine, where it may logically stand to reason you may have separate interfaces for a person conducting a &lt;br /&gt;
&lt;br /&gt;
1) Deposit Transaction, &lt;br /&gt;
&lt;br /&gt;
2) Withdrawal Transaction, and &lt;br /&gt;
&lt;br /&gt;
3) Transfer Transaction.  &lt;br /&gt;
&lt;br /&gt;
You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need.&lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Comparision of Aptana,Netbeans and Rubymine=&lt;br /&gt;
&lt;br /&gt;
Three IDEs namely Aptana's Radrails, Netbeans and Rubymine are compared in the following sections.&lt;br /&gt;
==System Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
==Features for Ruby==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other Features available in IDE's=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27558</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27558"/>
		<updated>2009-11-17T20:09:40Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* Clients Should not be forced to use Interface they don't use */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
This page tries to review Integrated Development Environments for Ruby such as Aptana,Rubymine and Netbeans. Also the IDEs are compared with respect to certain dimensions such as facilities, ease of use, system requirements, and support for the Ruby way of thinking.&lt;br /&gt;
&lt;br /&gt;
=Interface Segregation Principle= &lt;br /&gt;
* “Many client specific interfaces are better than one general purpose interface“&lt;br /&gt;
* “The dependency of one class to another one should depend on the smallest possible interface“&lt;br /&gt;
* “Make fine grained interfaces that are client specific.“&lt;br /&gt;
* “Clients should not be forced to depend upon interfaces that they don’t use. This principle deals with the disadvantages of fat interfaces. Fat interfaces are not cohesive. In other words the interfaces of classes should be broken into groups of member functions.“&lt;br /&gt;
&lt;br /&gt;
Here is an example of the Interface-Segregation Principle.  Consider a User interface for ATM machine, where it may logically stand to reason you may have separate interfaces for a person conducting a 1) Deposit Transaction, 2) Withdrawal Transaction, and 3) Transfer Transaction.  You would definitely separate these 3 interfaces from each other so that one type of transaction does not depend on functions it does not need.&lt;br /&gt;
&lt;br /&gt;
When clients are forced to depend upon interfaces that they don’t use, then those clients are subject to changes to those interfaces. This results in an inadvertent coupling between all the clients. Said another way, when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class. We would like to avoid such couplings where possible, and so we want to separate the interfaces where possible.&lt;br /&gt;
&lt;br /&gt;
==Clients Should not be forced to use Interface they don't use==&lt;br /&gt;
&lt;br /&gt;
To explain this consider the following Java Code&lt;br /&gt;
&lt;br /&gt;
 interface IWorker extends Feedable, Workable {&lt;br /&gt;
 }&lt;br /&gt;
 interface IWorkable {&lt;br /&gt;
 	public void work();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 interface IFeedable{&lt;br /&gt;
 	public void eat();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Worker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Robot implements IWorkable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		// ....working&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class SuperWorker implements IWorkable, IFeedable{&lt;br /&gt;
 	public void work() {&lt;br /&gt;
 		//.... working much more&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void eat() {&lt;br /&gt;
 		//.... eating in launch break&lt;br /&gt;
 	}&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 class Manager {&lt;br /&gt;
 	Workable worker;&lt;br /&gt;
 &lt;br /&gt;
 	public void setWorker(Workable w) {&lt;br /&gt;
 		worker=w;&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	public void manage() {&lt;br /&gt;
 		worker.work();&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=Comparision of Aptana,Netbeans and Rubymine=&lt;br /&gt;
&lt;br /&gt;
Three IDEs namely Aptana's Radrails, Netbeans and Rubymine are compared in the following sections.&lt;br /&gt;
==System Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
==Features for Ruby==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other Features available in IDE's=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27442</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27442"/>
		<updated>2009-11-17T18:32:01Z</updated>

		<summary type="html">&lt;p&gt;Maverick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Interface Segregation Principle vs. Principle of Small Interfaces'''''&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27419</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 8 ISPPSI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_8_ISPPSI&amp;diff=27419"/>
		<updated>2009-11-17T18:27:22Z</updated>

		<summary type="html">&lt;p&gt;Maverick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Interface Segregation Principle vs. Principle of Small Interfaces&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25883</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25883"/>
		<updated>2009-10-14T03:01:21Z</updated>

		<summary type="html">&lt;p&gt;Maverick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
        def initialize&lt;br /&gt;
           @@counter += 1&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        def getCounterValue&lt;br /&gt;
           puts @@counter&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
        ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
           if x.name == classname&lt;br /&gt;
           object = x.new&lt;br /&gt;
           object.getCounterValue&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
    def to_s&lt;br /&gt;
       value.to_s&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
   def initialize(arr)&lt;br /&gt;
      @arr = arr&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def play&lt;br /&gt;
      @arr.join('')&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
    Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
    chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
====WSDL, SOAP and UDDI in Ruby====&lt;br /&gt;
Consider the following example of a  [http://www.brics.dk/~amoeller/WWW/webservices/wsdlexample.html wsdl file].&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is parsed by using the REXML api and then using the '''''SOAP4R''''' library one can invoke the service. One can also use '''''WSDL4R''''' library to directly create the Ruby code for identifying the Name of the service, the elements and I/O objects. Below is a sample code on how a SOAP call is made using the SOAP4R library&lt;br /&gt;
&lt;br /&gt;
 class ServiceRequestController &amp;lt; ApplicationController&lt;br /&gt;
  @apiKey  = &amp;quot;StockQuoteService&amp;quot;&lt;br /&gt;
  def requestAService&lt;br /&gt;
   @wsdlUrl = &amp;quot;abc&amp;quot;&lt;br /&gt;
   driver = SOAP::WSDLDriverFactory.new(@wsdlUrl).create_rpc_driver&lt;br /&gt;
   driver.add_method('GetLastTradePriceInput',:tradePriceRequestObject)&lt;br /&gt;
   driver.GetLastTradePriceInput(tradePriceRequestObject)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Here the method name is found by parsing the wsdl file to get the '''message name'''. The children of this node are the parameters and o/p that the method returns.&lt;br /&gt;
Thus by using &amp;lt;code&amp;gt;add_method&amp;lt;/code&amp;gt; one could dynamically add a method to a class and invoke it.&lt;br /&gt;
&lt;br /&gt;
The WSDL4R is packaged with SOAP4R library. This is because all the information needed for invoking a service is same and one can have a same implementation for all the services. This is made possible due to the DuckTyping nature of Ruby.&lt;br /&gt;
&lt;br /&gt;
UDDI is one link that is not yet discussed. As mentioned earlier there has to be one single place where one can find all the information for the service if one is going to communicate with different businesses. The below sample code illustrates how the list of businesses and the services that are available and can be looked up [http://uddi4r.rubyforge.org/ ]&lt;br /&gt;
 &lt;br /&gt;
 require &amp;quot;lib/client&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # create the client&lt;br /&gt;
 uddi = Uddi4r::Client.new(&amp;quot;http://uddi.xmethods.net/inquire&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # find first matching business&lt;br /&gt;
 list = uddi.find_business(:name=&amp;gt;&amp;quot;chaiwat&amp;quot;)&lt;br /&gt;
 biz = list.business_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # find first service&lt;br /&gt;
 service = biz.service_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # and it's binding&lt;br /&gt;
 binding = uddi.find_binding(service.service_key)&lt;br /&gt;
 template = binding.binding_template.first()&lt;br /&gt;
 puts template.access_point()&lt;br /&gt;
&lt;br /&gt;
This uses the UDDI4R library to parse the UDDI registry given by http://uddi.xmethods.net/inquire and identify the Business names and the services. Once Identified one can use the SOAP4R or WSDL4R libraries to make the remote calls.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Reflection and Meta programming assist the implementation of the SOA philosophy. On the outset, it seems as if Metaprogramming and reflection are the different names for the same thing, but it will be safe to say that Reflection is a stronger form of Metaprogramming. As metaprogramming and reflection are powerful, so is their resource utilization. One has to take extreme caution and should use Reflection when the situation warrants for no other technique. Even while implementing SOA, the components that are on the web-services tier i.e. the tier which communicates with the external consumers or service providers, should be implemented using the reflection. &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
1] SOA with Ruby at �erubycon on �July 18, 2007 by Zak Mandhro �Senior Manager �BearingPoint, Inc&lt;br /&gt;
&lt;br /&gt;
2] [http://www.service-architecture.com/web-services/articles/service-oriented_architecture_soa_definition.html SOA and Web Services]&lt;br /&gt;
&lt;br /&gt;
3] Programming Ruby 1.9 by Dave Thomas, with Chad Fowler and Andy Hunt&lt;br /&gt;
&lt;br /&gt;
4] [http://soa.sys-con.com/node/39831 Web Services Made Easy]&lt;br /&gt;
&lt;br /&gt;
5] Ruby On Rails Power By Aneesha Bakharia&lt;br /&gt;
&lt;br /&gt;
6] Rails for Java Developers&lt;br /&gt;
&lt;br /&gt;
7] [http://en.wikipedia.org/wiki/Reflection_(computer_science) Reflection Oriented Programming]&lt;br /&gt;
&lt;br /&gt;
8] [http://nvisia.com/techs/?p=42 Shortcomings of Reflection]&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25621</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25621"/>
		<updated>2009-10-11T02:07:19Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* WSDL, SOAP and UDDI in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
====WSDL, SOAP and UDDI in Ruby====&lt;br /&gt;
Consider the following example of a  [http://www.brics.dk/~amoeller/WWW/webservices/wsdlexample.html wsdl file].&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is parsed by using the REXML api and then using the '''''SOAP4R''''' library one can invoke the service. One can also use '''''WSDL4R''''' library to directly create the Ruby code for identifying the Name of the service, the elements and I/O objects. Below is a sample code on how a SOAP call is made using the SOAP4R library&lt;br /&gt;
&lt;br /&gt;
 class ServiceRequestController &amp;lt; ApplicationController&lt;br /&gt;
  @apiKey  = &amp;quot;StockQuoteService&amp;quot;&lt;br /&gt;
  def requestAService&lt;br /&gt;
   @wsdlUrl = &amp;quot;abc&amp;quot;&lt;br /&gt;
   driver = SOAP::WSDLDriverFactory.new(@wsdlUrl).create_rpc_driver&lt;br /&gt;
   driver.add_method('GetLastTradePriceInput',:tradePriceRequestObject)&lt;br /&gt;
   driver.GetLastTradePriceInput(tradePriceRequestObject)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Here the method name is found by parsing the wsdl file to get the '''message name'''. The children of this node are the parameters and o/p that the method returns.&lt;br /&gt;
Thus by using &amp;lt;code&amp;gt;add_method&amp;lt;/code&amp;gt; one could dynamically add a method to a class and invoke it.&lt;br /&gt;
&lt;br /&gt;
The WSDL4R is packaged with SOAP4R library. This is because all the information needed for invoking a service is same and one can have a same implementation for all the services. This is made possible due to the DuckTyping nature of Ruby.&lt;br /&gt;
&lt;br /&gt;
UDDI is one link that is not yet discussed. As mentioned earlier there has to be one single place where one can find all the information for the service if one is going to communicate with different businesses. The below sample code illustrates how the list of businesses and the services that are available and can be looked up [http://uddi4r.rubyforge.org/ ]&lt;br /&gt;
 &lt;br /&gt;
 require &amp;quot;lib/client&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # create the client&lt;br /&gt;
 uddi = Uddi4r::Client.new(&amp;quot;http://uddi.xmethods.net/inquire&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # find first matching business&lt;br /&gt;
 list = uddi.find_business(:name=&amp;gt;&amp;quot;chaiwat&amp;quot;)&lt;br /&gt;
 biz = list.business_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # find first service&lt;br /&gt;
 service = biz.service_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # and it's binding&lt;br /&gt;
 binding = uddi.find_binding(service.service_key)&lt;br /&gt;
 template = binding.binding_template.first()&lt;br /&gt;
 puts template.access_point()&lt;br /&gt;
&lt;br /&gt;
This uses the UDDI4R library to parse the UDDI registry given by http://uddi.xmethods.net/inquire and identify the Business names and the services. Once Identified one can use the SOAP4R or WSDL4R libraries to make the remote calls.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
1] SOA with Ruby at �erubycon on �July 18, 2007 by Zak Mandhro �Senior Manager �BearingPoint, Inc&lt;br /&gt;
&lt;br /&gt;
2] [http://www.service-architecture.com/web-services/articles/service-oriented_architecture_soa_definition.html SOA and Web Services]&lt;br /&gt;
&lt;br /&gt;
3] Programming Ruby 1.9 by Dave Thomas, with Chad Fowler and Andy Hunt&lt;br /&gt;
&lt;br /&gt;
4] [http://soa.sys-con.com/node/39831 Web Services Made Easy]&lt;br /&gt;
&lt;br /&gt;
5] Ruby On Rails Power By Aneesha Bakharia&lt;br /&gt;
&lt;br /&gt;
6] Rails for Java Developers&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25595</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25595"/>
		<updated>2009-10-10T04:54:21Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===WSDL, SOAP and UDDI in Ruby===&lt;br /&gt;
Consider the following example of a  [http://www.brics.dk/~amoeller/WWW/webservices/wsdlexample.html wsdl file].&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is parsed by using the REXML api and then using the '''''SOAP4R''''' library one can invoke the service. One can also use '''''WSDL4R''''' library to directly create the Ruby code for identifying the Name of the service, the elements and I/O objects. Below is a sample code on how a SOAP call is made using the SOAP4R library&lt;br /&gt;
&lt;br /&gt;
 class ServiceRequestController &amp;lt; ApplicationController&lt;br /&gt;
  @apiKey  = &amp;quot;StockQuoteService&amp;quot;&lt;br /&gt;
  def requestAService&lt;br /&gt;
   @wsdlUrl = &amp;quot;abc&amp;quot;&lt;br /&gt;
   driver = SOAP::WSDLDriverFactory.new(@wsdlUrl).create_rpc_driver&lt;br /&gt;
   driver.add_method('GetLastTradePriceInput',:tradePriceRequestObject)&lt;br /&gt;
   driver.GetLastTradePriceInput(tradePriceRequestObject)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Here the method name is found by parsing the wsdl file to get the '''message name'''. The children of this node are the parameters and o/p that the method returns.&lt;br /&gt;
Thus by using &amp;lt;code&amp;gt;add_method&amp;lt;/code&amp;gt; one could dynamically add a method to a class and invoke it.&lt;br /&gt;
&lt;br /&gt;
The WSDL4R is packaged with SOAP4R library. This is because all the information needed for invoking a service is same and one can have a same implementation for all the services. This is made possible due to the DuckTyping nature of Ruby.&lt;br /&gt;
&lt;br /&gt;
UDDI is one link that is not yet discussed. As mentioned earlier there has to be one single place where one can find all the information for the service if one is going to communicate with different businesses. The below sample code illustrates how the list of businesses and the services that are available and can be looked up [http://uddi4r.rubyforge.org/ ]&lt;br /&gt;
 &lt;br /&gt;
 require &amp;quot;lib/client&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # create the client&lt;br /&gt;
 uddi = Uddi4r::Client.new(&amp;quot;http://uddi.xmethods.net/inquire&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # find first matching business&lt;br /&gt;
 list = uddi.find_business(:name=&amp;gt;&amp;quot;chaiwat&amp;quot;)&lt;br /&gt;
 biz = list.business_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # find first service&lt;br /&gt;
 service = biz.service_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # and it's binding&lt;br /&gt;
 binding = uddi.find_binding(service.service_key)&lt;br /&gt;
 template = binding.binding_template.first()&lt;br /&gt;
 puts template.access_point()&lt;br /&gt;
&lt;br /&gt;
This uses the UDDI4R library to parse the UDDI registry given by http://uddi.xmethods.net/inquire and identify the Business names and the services. Once Identified one can use the SOAP4R or WSDL4R libraries to make the remote calls.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
1] SOA with Ruby at �erubycon on �July 18, 2007 by Zak Mandhro �Senior Manager �BearingPoint, Inc&lt;br /&gt;
&lt;br /&gt;
2] [http://www.service-architecture.com/web-services/articles/service-oriented_architecture_soa_definition.html SOA and Web Services]&lt;br /&gt;
&lt;br /&gt;
3] Programming Ruby 1.9 by Dave Thomas, with Chad Fowler and Andy Hunt&lt;br /&gt;
&lt;br /&gt;
4] [http://soa.sys-con.com/node/39831 Web Services Made Easy]&lt;br /&gt;
&lt;br /&gt;
5] Ruby On Rails Power By Aneesha Bakharia&lt;br /&gt;
&lt;br /&gt;
6] Rails for Java Developers&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25589</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25589"/>
		<updated>2009-10-10T04:11:32Z</updated>

		<summary type="html">&lt;p&gt;Maverick: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===WSDL, SOAP and UDDI in Ruby===&lt;br /&gt;
Consider the following example of a  [http://www.brics.dk/~amoeller/WWW/webservices/wsdlexample.html wsdl file].&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is parsed by using the REXML api and then using the '''''SOAP4R''''' library one can invoke the service. One can also use '''''WSDL4R''''' library to directly create the Ruby code for identifying the Name of the service, the elements and I/O objects. Below is a sample code on how a SOAP call is made using the SOAP4R library&lt;br /&gt;
&lt;br /&gt;
 class ServiceRequestController &amp;lt; ApplicationController&lt;br /&gt;
  @apiKey  = &amp;quot;StockQuoteService&amp;quot;&lt;br /&gt;
  def requestAService&lt;br /&gt;
   @wsdlUrl = &amp;quot;abc&amp;quot;&lt;br /&gt;
   driver = SOAP::WSDLDriverFactory.new(@wsdlUrl).create_rpc_driver&lt;br /&gt;
   driver.add_method('GetLastTradePriceInput',:tradePriceRequestObject)&lt;br /&gt;
   driver.GetLastTradePriceInput(tradePriceRequestObject)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Here the method name is found by parsing the wsdl file to get the '''message name'''. The children of this node are the parameters and o/p that the method returns.&lt;br /&gt;
Thus by using &amp;lt;code&amp;gt;add_method&amp;lt;/code&amp;gt; one could dynamically add a method to a class and invoke it.&lt;br /&gt;
&lt;br /&gt;
The WSDL4R is packaged with SOAP4R library. This is because all the information needed for invoking a service is same and one can have a same implementation for all the services. This is made possible due to the DuckTyping nature of Ruby.&lt;br /&gt;
&lt;br /&gt;
UDDI is one link that is not yet discussed. As mentioned earlier there has to be one single place where one can find all the information for the service if one is going to communicate with different businesses. The below sample code illustrates how the list of businesses and the services that are available and can be looked up [http://uddi4r.rubyforge.org/ ]&lt;br /&gt;
 &lt;br /&gt;
 require &amp;quot;lib/client&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # create the client&lt;br /&gt;
 uddi = Uddi4r::Client.new(&amp;quot;http://uddi.xmethods.net/inquire&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # find first matching business&lt;br /&gt;
 list = uddi.find_business(:name=&amp;gt;&amp;quot;chaiwat&amp;quot;)&lt;br /&gt;
 biz = list.business_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # find first service&lt;br /&gt;
 service = biz.service_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # and it's binding&lt;br /&gt;
 binding = uddi.find_binding(service.service_key)&lt;br /&gt;
 template = binding.binding_template.first()&lt;br /&gt;
 puts template.access_point()&lt;br /&gt;
&lt;br /&gt;
This uses the UDDI4R library to parse the UDDI registry given by http://uddi.xmethods.net/inquire and identify the Business names and the services. Once Identified one can use the SOAP4R or WSDL4R libraries to make the remote calls.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
1] SOA with Ruby at �erubycon on �July 18, 2007 by Zak Mandhro �Senior Manager �BearingPoint, Inc&lt;br /&gt;
2] [http://www.service-architecture.com/web-services/articles/service-oriented_architecture_soa_definition.html SOA and Web Services]&lt;br /&gt;
3] Programming Ruby 1.9 by Dave Thomas, with Chad Fowler and Andy Hunt&lt;br /&gt;
4] [http://soa.sys-con.com/node/39831 Web Services Made Easy]&lt;br /&gt;
5] Ruby On Rails Power By Aneesha Bakharia&lt;br /&gt;
6] Rails for Java Developers&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25584</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25584"/>
		<updated>2009-10-10T04:06:02Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* WSDL, SOAP and UDDI in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===WSDL, SOAP and UDDI in Ruby===&lt;br /&gt;
Consider the following example of a  [http://www.brics.dk/~amoeller/WWW/webservices/wsdlexample.html wsdl file].&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is parsed by using the REXML api and then using the '''''SOAP4R''''' library one can invoke the service. One can also use '''''WSDL4R''''' library to directly create the Ruby code for identifying the Name of the service, the elements and I/O objects. Below is a sample code on how a SOAP call is made using the SOAP4R library&lt;br /&gt;
&lt;br /&gt;
 class ServiceRequestController &amp;lt; ApplicationController&lt;br /&gt;
  @apiKey  = &amp;quot;StockQuoteService&amp;quot;&lt;br /&gt;
  def requestAService&lt;br /&gt;
   @wsdlUrl = &amp;quot;abc&amp;quot;&lt;br /&gt;
   driver = SOAP::WSDLDriverFactory.new(@wsdlUrl).create_rpc_driver&lt;br /&gt;
   driver.add_method('GetLastTradePriceInput',:tradePriceRequestObject)&lt;br /&gt;
   driver.GetLastTradePriceInput(tradePriceRequestObject)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Here the method name is found by parsing the wsdl file to get the '''message name'''. The children of this node are the parameters and o/p that the method returns.&lt;br /&gt;
Thus by using &amp;lt;code&amp;gt;add_method&amp;lt;/code&amp;gt; one could dynamically add a method to a class and invoke it.&lt;br /&gt;
&lt;br /&gt;
The WSDL4R is packaged with SOAP4R library. This is because all the information needed for invoking a service is same and one can have a same implementation for all the services. This is made possible due to the DuckTyping nature of Ruby.&lt;br /&gt;
&lt;br /&gt;
UDDI is one link that is not yet discussed. As mentioned earlier there has to be one single place where one can find all the information for the service if one is going to communicate with different businesses. The below sample code illustrates how the list of businesses and the services that are available and can be looked up [http://uddi4r.rubyforge.org/ ]&lt;br /&gt;
 &lt;br /&gt;
 require &amp;quot;lib/client&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # create the client&lt;br /&gt;
 uddi = Uddi4r::Client.new(&amp;quot;http://uddi.xmethods.net/inquire&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 # find first matching business&lt;br /&gt;
 list = uddi.find_business(:name=&amp;gt;&amp;quot;chaiwat&amp;quot;)&lt;br /&gt;
 biz = list.business_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # find first service&lt;br /&gt;
 service = biz.service_infos.first()&lt;br /&gt;
 &lt;br /&gt;
 # and it's binding&lt;br /&gt;
 binding = uddi.find_binding(service.service_key)&lt;br /&gt;
 template = binding.binding_template.first()&lt;br /&gt;
 puts template.access_point()&lt;br /&gt;
&lt;br /&gt;
This uses the UDDI4R library to parse the UDDI registry given by http://uddi.xmethods.net/inquire and identify the Business names and the services. Once Identified one can use the SOAP4R or WSDL4R libraries to make the remote calls.&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25575</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25575"/>
		<updated>2009-10-10T03:53:26Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* WSDL, SOAP and UDDI in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===WSDL, SOAP and UDDI in Ruby===&lt;br /&gt;
Consider the following example of a  [http://www.brics.dk/~amoeller/WWW/webservices/wsdlexample.html wsdl file].&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is parsed by using the REXML api and then using the '''''SOAP4R''''' library one can invoke the service. One can also use '''''WSDL4R''''' library to directly create the Ruby code for identifying the Name of the service, the elements and I/O objects. Below is a sample code on how a SOAP call is made using the SOAP4R library&lt;br /&gt;
&lt;br /&gt;
 class ServiceRequestController &amp;lt; ApplicationController&lt;br /&gt;
  @apiKey  = &amp;quot;StockQuoteService&amp;quot;&lt;br /&gt;
  def requestAService&lt;br /&gt;
   @wsdlUrl = &amp;quot;abc&amp;quot;&lt;br /&gt;
   driver = SOAP::WSDLDriverFactory.new(@wsdlUrl).create_rpc_driver&lt;br /&gt;
   driver.add_method('GetLastTradePriceInput',:tradePriceRequestObject)&lt;br /&gt;
   driver.GetLastTradePriceInput(tradePriceRequestObject)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Here the method name is found by parsing the wsdl file to get the '''message name'''. The children of this node are the parameters and o/p that the method returns.&lt;br /&gt;
Thus by using &amp;lt;code&amp;gt;add_method&amp;lt;/code&amp;gt; one could dynamically add a method to a class and invoke it.&lt;br /&gt;
&lt;br /&gt;
The WSDL4R is packaged with SOAP4R library. This is because all the information needed for invoking a service is same and one can have a same implementation for all the services. This is made possible due to the DuckTyping nature of Ruby.&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25572</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25572"/>
		<updated>2009-10-10T03:49:59Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* WSDL, SOAP and UDDI in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===WSDL, SOAP and UDDI in Ruby===&lt;br /&gt;
Consider the following example of a  [http://www.brics.dk/~amoeller/WWW/webservices/wsdlexample.html wsdl file].&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is parsed by using the REXML api for one can use '''''WSDL4R''''' library to directly create the Ruby code for identifying the Name of the service, the elements and I/O objects. Below is a sample code on how a SOAP call is made:&lt;br /&gt;
&lt;br /&gt;
 class ServiceRequestController &amp;lt; ApplicationController&lt;br /&gt;
  @apiKey  = &amp;quot;StockQuoteService&amp;quot;&lt;br /&gt;
  def requestAService&lt;br /&gt;
   @wsdlUrl = &amp;quot;abc&amp;quot;&lt;br /&gt;
   driver = SOAP::WSDLDriverFactory.new(@wsdlUrl).create_rpc_driver&lt;br /&gt;
   driver.add_method('GetLastTradePriceInput',:tradePriceRequestObject)&lt;br /&gt;
   driver.GetLastTradePriceInput(tradePriceRequestObject)&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Here the method name is found by parsing the wsdl file to get the '''message name'''. The children of this node are the parameters and o/p that the method returns.&lt;br /&gt;
Thus by using &amp;lt;code&amp;gt;add_method&amp;lt;/code&amp;gt; one could dynamically add a method to a class and invoke it.&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25557</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25557"/>
		<updated>2009-10-10T03:36:11Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* WSDL, SOAP and UDDI in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===WSDL, SOAP and UDDI in Ruby===&lt;br /&gt;
Consider the following example of a wsdl file.&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25555</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25555"/>
		<updated>2009-10-10T03:35:30Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* SOAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===WSDL, SOAP and UDDI in Ruby===&lt;br /&gt;
Consider the following example of a wsdl file.&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;definitions name=&amp;quot;StockQuote&amp;quot;&lt;br /&gt;
             targetNamespace=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:tns=&amp;quot;http://example.com/stockquote.wsdl&amp;quot;&lt;br /&gt;
             xmlns:xsd1=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
             xmlns:soap=&amp;quot;http://schemas.xmlsoap.org/wsdl/soap/&amp;quot;&lt;br /&gt;
             xmlns=&amp;quot;http://schemas.xmlsoap.org/wsdl/&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;types&amp;gt;&lt;br /&gt;
    &amp;lt;schema targetNamespace=&amp;quot;http://example.com/stockquote.xsd&amp;quot;&lt;br /&gt;
            xmlns=&amp;quot;http://www.w3.org/2000/10/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePriceRequest&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;complexType&amp;gt;&lt;br /&gt;
          &amp;lt;all&amp;gt;&lt;br /&gt;
            &amp;lt;element name=&amp;quot;tickerSymbol&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;/all&amp;gt;&lt;br /&gt;
        &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
      &amp;lt;element name=&amp;quot;TradePrice&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;complexType&amp;gt;&lt;br /&gt;
           &amp;lt;all&amp;gt;&lt;br /&gt;
             &amp;lt;element name=&amp;quot;price&amp;quot; type=&amp;quot;float&amp;quot;/&amp;gt;&lt;br /&gt;
           &amp;lt;/all&amp;gt;&lt;br /&gt;
         &amp;lt;/complexType&amp;gt;&lt;br /&gt;
      &amp;lt;/element&amp;gt;&lt;br /&gt;
    &amp;lt;/schema&amp;gt;&lt;br /&gt;
  &amp;lt;/types&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceInput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePriceRequest&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;message name=&amp;quot;GetLastTradePriceOutput&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;part name=&amp;quot;body&amp;quot; element=&amp;quot;xsd1:TradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/message&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;portType name=&amp;quot;StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input message=&amp;quot;tns:GetLastTradePriceInput&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;output message=&amp;quot;tns:GetLastTradePriceOutput&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/portType&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;binding name=&amp;quot;StockQuoteSoapBinding&amp;quot; type=&amp;quot;tns:StockQuotePortType&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;soap:binding style=&amp;quot;document&amp;quot; transport=&amp;quot;http://schemas.xmlsoap.org/soap/http&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;operation name=&amp;quot;GetLastTradePrice&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:operation soapAction=&amp;quot;http://example.com/GetLastTradePrice&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
        &amp;lt;soap:body use=&amp;quot;literal&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
    &amp;lt;/operation&amp;gt;&lt;br /&gt;
  &amp;lt;/binding&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;service name=&amp;quot;StockQuoteService&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;documentation&amp;gt;My first service&amp;lt;/documentation&amp;gt;&lt;br /&gt;
    &amp;lt;port name=&amp;quot;StockQuotePort&amp;quot; binding=&amp;quot;tns:StockQuoteSoapBinding&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;soap:address location=&amp;quot;http://example.com/stockquote&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/port&amp;gt;&lt;br /&gt;
  &amp;lt;/service&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/definitions&amp;gt;&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25550</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25550"/>
		<updated>2009-10-10T03:32:52Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* XML Parsing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;br /&gt;
The code by use of this library is just like one-one mapping between the Domain object and the elements of the XML.&lt;br /&gt;
&lt;br /&gt;
===SOAP===&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25548</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25548"/>
		<updated>2009-10-10T03:31:25Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* == */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries.&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25547</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 17 f1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_17_f1&amp;diff=25547"/>
		<updated>2009-10-10T03:31:14Z</updated>

		<summary type="html">&lt;p&gt;Maverick: /* XML Parsing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Service Oriented Architecture provides another view of providing functionality based upon services offered in terms of protocols and a specific API. To provide services, platforms rely upon principles and the power that can be expressed through reflection and meta programming. Research and report how these critical concepts relate to and support SOA.'''&lt;br /&gt;
&lt;br /&gt;
== Service Oriented Architectures==&lt;br /&gt;
Service Oriented Architecture is not a new thing, but has been there since around 1991 by virtue of the [http://www.omg.org/gettingstarted/history_of_corba.htm CORBA specifications]. The earliest SOA architectures were, DCOM and CORBA [http://www.service-architecture.com/web-services/articles/prior_service-oriented_architecture_specifications.html 1]. [http://en.wikipedia.org/wiki/Service_Oriented_Architectures Service Oriented Architecture] (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. SOA provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations. It is a collection of services. These services communicate with each other either by simple data passing or it could involve two or more services coordinating some activity by means of some predefined standard connecting services.  This makes it easier for software integration of different modules developed by different people. Rather than defining an [http://en.wikipedia.org/wiki/API &lt;br /&gt;
API], SOA defines the interface in terms of protocols and functionality such that modules following these protocols can easily be integrated together. &lt;br /&gt;
The typical SOA implementation can be illustrated in the figure:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Service-oriented_architecture_basics.jpg|SOA Functioning]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main characteristics of SOA are:&lt;br /&gt;
&lt;br /&gt;
* '''Based on open standards''' - The governing principles are free for all to use and not protected by intellectual property.&lt;br /&gt;
* '''Interoperable''' - Diverse systems should be able to work together (inter-operate)&lt;br /&gt;
* '''Autonomous''' - Services have control over the logic they encapsulate.&lt;br /&gt;
* '''Reusable''' - Logic is divided into services with the intention of promoting reuse.&lt;br /&gt;
* '''Reliable''' - It should not have many flaws&lt;br /&gt;
* '''Discoverable''' - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms&lt;br /&gt;
* '''Loosely-Coupled''' - Loose coupling occurs when the dependent class contains a pointer only to an interface, which can then be implemented by one or many concrete classes.&lt;br /&gt;
* '''Stateless''' - Should exhibit the same behaviour and yield the same result whether called once, or 100 times&lt;br /&gt;
* '''Composable''' - Collections of services can be coordinated and assembled to form composite services.&lt;br /&gt;
* '''Manageable''' - It should be easy to maintain it&lt;br /&gt;
* '''Secure''' - It should not be easily hackable&lt;br /&gt;
&lt;br /&gt;
=== Core Components of SOA===&lt;br /&gt;
As mentioned earlier, the services communicate with each other using a predefined protocol. The techniques used for protocol selection and execution form the core components of SOA. While using SOA, we have a service that has tells the type of service its provides using [http://en.wikipedia.org/wiki/Web_Services_Description_Language Web Services Description Language (WSDL)] and a directory, like [http://www.service-architecture.com/web-services/articles/universal_description_discovery_and_integration_uddi.html Universal Description, Discovery, and Integration (UDDI)] that holds this information. The service consumer (one who wants some service) will lookup this directory for the name of the service that can fulfill the consumer's request. The consumer and the service provider communicate using some format (in layman terms a language) like SOAP. These ideology leads to the following components of a SOA implementation.&lt;br /&gt;
&lt;br /&gt;
* '''SOAP''': Simple Object Access Protocol - As a layman's example of how SOAP procedures can be used, a SOAP message could be sent to a web service enabled web site (for example, a house price database) with the parameters needed for a search. The site would then return an [http://en.wikipedia.org/wiki/XML XML]-formatted document with the resulting data (prices, location, features, etc). Because the data is returned in a standardized machine-parseable format, it could then be integrated directly into a third-party site.&lt;br /&gt;
* '''WSDL''': Web Services Description Language - Its an XML-based language that provides a model for describing Web Services.&lt;br /&gt;
* '''UDDI''': Universal Discovery, Definition and Integration - Its an XML-based database for companies world-wide to list themselves on the internet&lt;br /&gt;
* '''BPEL''': Business Process Execution Language - Its a language for specifying interaction with web services.&lt;br /&gt;
* '''ESB''': [http://en.wikipedia.org/wiki/Enterprise_service_bus Enterprise Service Bus] &lt;br /&gt;
* '''WS-*''': Web Services Standards - a collection of protocols and standards used for exchanging data between applications&lt;br /&gt;
&lt;br /&gt;
===Benefits of SOA ===&lt;br /&gt;
The benefits offered by SOA can be directly derived from the characteristics of SOA. The features like loose coupling between the service requests and service provider implies flexibility and reuse of services for different service consumers. The benefits can be summarized as below:&lt;br /&gt;
* Improve long-term value of software assets&lt;br /&gt;
* Improve quality through modularity and testability&lt;br /&gt;
* Reduce development time with composition and re-usability&lt;br /&gt;
* Leverage heterogeneous development environments&lt;br /&gt;
* Avoid vendor and platform lock-in&lt;br /&gt;
* Integrate with [http://en.wikipedia.org/wiki/Enterprise_resource_planning ERPs] and Enterprise infrastructure software&lt;br /&gt;
&lt;br /&gt;
===Use cases for SOA with Ruby===&lt;br /&gt;
Ruby can be a productive way to:&lt;br /&gt;
* Build web applications over web services&lt;br /&gt;
* Write web services tests with minimal code&lt;br /&gt;
* Write custom web services monitoring and management&lt;br /&gt;
* Integrate ERPs, [http://en.wikipedia.org/wiki/Commercial_off-the-shelf COTS] and custom applications&lt;br /&gt;
* Write SOA glue-code, e.g. custom transformation&lt;br /&gt;
* Perform programmatic web services orchestration&lt;br /&gt;
* Develop basic web services&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
&lt;br /&gt;
One of the many advantages of dynamic languages such as Ruby is the ability to introspect—to examine aspects of the program from within the program itself. This is called reflection. At runtime, we can discover the following things about our ruby program - &lt;br /&gt;
* what objects it contains,&lt;br /&gt;
* the class hierarchy,&lt;br /&gt;
* the attributes and methods of objects, and&lt;br /&gt;
* information on methods.&lt;br /&gt;
&lt;br /&gt;
Ruby provide a module called &amp;quot;ObjectSpace&amp;quot; that lets you to use reflection and see all the above mentioned information. So if you say, &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object { |x| puts x }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all living, nonimmediate objects in Ruby process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectSpace.each_object(Class) { |x| puts x}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will print all classes in Ruby process.&lt;br /&gt;
&lt;br /&gt;
The following code iterates over all the classes, compares their name. If name matches then create object and execute whichever function you like. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    class ClassFromString&lt;br /&gt;
    @@counter = 0&lt;br /&gt;
    def initialize&lt;br /&gt;
    @@counter += 1&lt;br /&gt;
    end&lt;br /&gt;
    def getCounterValue&lt;br /&gt;
    puts @@counter&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def createClassFromString(classname)&lt;br /&gt;
    ObjectSpace.each_object(Class) do |x|&lt;br /&gt;
    if x.name == classname&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    object = x.new&lt;br /&gt;
    object.getCounterValue&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
    createClassFromString(&amp;quot;ClassFromString&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you get the object you can use any method of that object. For e.g. you can use superclass method to get the name of the parent class and so on and can build complete hierarchy dynamically.&lt;br /&gt;
You can get the information about methods of a given class using methods like private_methods(), protected_methods() which are defined in Object class which is base class for each object.&lt;br /&gt;
&lt;br /&gt;
'''Distributed Ruby''' and '''Marshalling''' are two reflection-based technologies that let us send objects around the world and through time, which enables use of Service Oriented Architectures.&lt;br /&gt;
&lt;br /&gt;
===Marshalling===&lt;br /&gt;
&lt;br /&gt;
Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed.&lt;br /&gt;
To &amp;quot;serialize&amp;quot; an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.  You can use this facility, for instance, to save a tree of objects that represent some portion of application state—a document, a CAD drawing, a piece of music, and so on.&lt;br /&gt;
Ruby calls this kind of serialization marshaling (think of railroad marshaling yards where individual cars are assembled in sequence into a complete train, which is then dispatched somewhere). Saving an object and some or all of its components is done using the method ''Marshal.dump''. Typically, you will dump an entire object tree starting with some given object. Later, you can reconstitute the object using ''Marshal.load''.&lt;br /&gt;
&lt;br /&gt;
Example -  &lt;br /&gt;
&lt;br /&gt;
We have a class Chord that holds a collection of musical notes. We’d like to save away a particularly wonderful chord so we can e-mail it to friends. They can then load it into their copy of Ruby and savor it too. Let’s start with the classes for Note and Chord.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note = Struct.new(:value)&lt;br /&gt;
class Note&lt;br /&gt;
def to_s&lt;br /&gt;
value.to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Chord&lt;br /&gt;
def initialize(arr)&lt;br /&gt;
@arr = arr&lt;br /&gt;
end&lt;br /&gt;
def play&lt;br /&gt;
@arr.join('')&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we’ll create our masterpiece and use Marshal.dump to save a serialized version of it to disk.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c = Chord.new( [ Note.new(&amp;quot;G&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Bb&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;Db&amp;quot;),&lt;br /&gt;
Note.new(&amp;quot;E&amp;quot;) ] )&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;, &amp;quot;w+&amp;quot;) do |f|&lt;br /&gt;
Marshal.dump(c, f)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, it can be read by our friends.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File.open(&amp;quot;posterity&amp;quot;) do |f|&lt;br /&gt;
chord = Marshal.load(f)&lt;br /&gt;
end&lt;br /&gt;
chord.play ! &amp;quot;GBbDbE&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Distributed Ruby ===&lt;br /&gt;
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation (RMI) to pass commands and data between processes. Since we can serialize an object or a set of objects into a form suitable for out-ofprocess storage, we can use this capability for the transmission of objects from one  process to another. Using drb, a Ruby process may act as a server, as a client, or as both. A drb server acts as a source of objects, while a client is a user of those objects. To the client, it appears&lt;br /&gt;
that the objects are local, but in reality the code is still being executed remotely. This can be found in the SOAP implementation of RUBY libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming and SOA==&lt;br /&gt;
The non - dependence of service consumers with service providers during compile time causes a dynamic runtime binding. Invocation of a wide range of service providers calls for techniques that can help creation of service requests at runtime for compatibility with the binding identified during runtime. This can be achieved by using the technique of Metaprogramming. &amp;quot;Meta&amp;quot; means &amp;quot;self&amp;quot; and hence meta programming can be stated as self programming or program that codes itself. This means that there will be some set of code which will create code at runtime. Using this we can create code that binds the service consumer with service provider.&lt;br /&gt;
The concept of meta programming is explained by using Ruby language.&lt;br /&gt;
&lt;br /&gt;
===Metaprogramming in Ruby===&lt;br /&gt;
Metaprogramming is inbuilt and used extensively by the language itself. Consider the following standard used syntax to create getters and setters in ruby:&lt;br /&gt;
&amp;quot;&amp;lt;code&amp;gt;attr_writer :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_reader :a&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;attr_accessor :b&amp;lt;/code&amp;gt;&amp;quot;. Each of the single lines of code creates the accessor or/and mutators methods for the variables. This is an example of '''''Metaprogramming'''''. The logic written by the base ruby code (in &amp;lt;code&amp;gt;object.c&amp;lt;/code&amp;gt; file in the ruby directory) uses the information about the variable name provided by the developer and creates at runtime the accessor and mutator methods. This is at runtime as physically there is no code which is present.&lt;br /&gt;
Metaprogramming is achieved by the &amp;lt;code&amp;gt;eval&amp;lt;/code&amp;gt; method provided by the Ruby language. &lt;br /&gt;
 class GreetPeople&lt;br /&gt;
  eval %{def greeting puts &amp;quot;Hello All!&amp;quot; end}&lt;br /&gt;
 end&lt;br /&gt;
 me = GreetPeople.new&lt;br /&gt;
 puts me.hi&lt;br /&gt;
&lt;br /&gt;
''produces'' '''''Hello All!'''''&lt;br /&gt;
&lt;br /&gt;
One can use &amp;lt;code&amp;gt;define_method&amp;lt;/code&amp;gt; to generate classes and methods at runtime. The usage is like below&lt;br /&gt;
 class Logger&lt;br /&gt;
   def self.add_logging(id_string)&lt;br /&gt;
     define_method(:log) do |msg|&lt;br /&gt;
       now = Time.now.strftime(&amp;quot;%H:%M:%S&amp;quot;) &lt;br /&gt;
       STDERR.puts &amp;quot;#{now}-#{id_string}: #{self} (#{msg})&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Song &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;Tune&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Album &amp;lt; Logger&lt;br /&gt;
  add_logging &amp;quot;CD&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 song = Song.new&lt;br /&gt;
 song.log(&amp;quot;rock on&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The output produced is:&lt;br /&gt;
 13:26:13-Tune: #&amp;lt;Song:0x0a20e4&amp;gt; (rock on)&lt;br /&gt;
&lt;br /&gt;
Look the part &amp;lt;code&amp;gt;#&amp;lt;Song:0x0a20e4&amp;gt;&amp;lt;/code&amp;gt; even if there is no mention of the class Song, the logger method printed the name of the class as it picked it up at runtime from the keyword '''&amp;quot;self&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
Other methods like add_method adds method to the a class at runtime.&lt;br /&gt;
&lt;br /&gt;
===SOA with Ruby===&lt;br /&gt;
Ruby has some standard libraries for each functional block in the SOA architecture. These libraries are&lt;br /&gt;
 XML 1.0 - REXML, others&lt;br /&gt;
 SOAP 1.1 - SOAP4R, AWS&lt;br /&gt;
 WSDL 1.1 - WSDL4R, AWS&lt;br /&gt;
 UDDI V2 - UDDI4R&lt;br /&gt;
&lt;br /&gt;
Each of these libraries use Metaprogramming in some form or the other. Below is the description for each of the libraries&lt;br /&gt;
====XML Parsing====&lt;br /&gt;
XML is the foundation for the web services. The request, identification of service, method and its parameters of the service, the response, all are in the form of an xml. Thus XML parsing and construction is very important part for effective SOA implementation. &lt;br /&gt;
The XML parsing is handled by the REXML library which is coded in native Ruby code and hence is slow.&lt;br /&gt;
&lt;br /&gt;
The sample code for parsing is&lt;br /&gt;
 require 'rexml/document'&lt;br /&gt;
 xml = &amp;quot;&amp;lt;xml&amp;gt;&amp;lt;person&amp;gt;Abc Xyz&amp;lt;/person&amp;gt;&amp;lt;/xml&amp;gt;&lt;br /&gt;
 begin&lt;br /&gt;
   REXML::Document.new(xml)&lt;br /&gt;
 rescue REXML::ParseException&lt;br /&gt;
   puts &amp;quot;Error occured&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
At runtime the code identifies the nodes and children for each node which can be converted into a collections object for usage and identifying the names and values for each element.&lt;br /&gt;
&lt;br /&gt;
While reading an XML, the use of REXML results in a complex piece of code. Life can be made much simpler by use of '''Builder::XmlMarkup''' libraries. &lt;br /&gt;
====&lt;/div&gt;</summary>
		<author><name>Maverick</name></author>
	</entry>
</feed>