CSC/ECE 517 Fall 2010/ch7 7d tt: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 3: Line 3:
The indirection pattern is used when data should not be a part of a class but rather contained within its own module. Additionally, indirection is a pattern when 2 or more modules do not interact directly but allow for a separate module to communicate between them. The ultimate result is loose coupling. Similar GRASP patterns are Proxy, Delegation, Bridge and Mediator [1, 2].
The indirection pattern is used when data should not be a part of a class but rather contained within its own module. Additionally, indirection is a pattern when 2 or more modules do not interact directly but allow for a separate module to communicate between them. The ultimate result is loose coupling. Similar GRASP patterns are Proxy, Delegation, Bridge and Mediator [1, 2].


The indirection pattern is a pattern that has been used in the GRASP [3]. GRASP stands for General Responsibility Assignment Software Patterns. GRASP principles list the guidelines for efficient object-oriented programming. Indirection pattern is essentially used to separate the entities in a class that are logically bound to each other into simpler entities, so as to divide the work done by the class. At the same time it is ensured that the cohesion of the data resources that have been broken into simple pieces remains high [3]. A very good example which implements the Indirection pattern is the Model-View-Controller pattern, where there are two components namely the Model and the View for every class. The Model represents the data of the class and the View denotes the representation of the class when a user interacts with the class. The Controller component is the intermediate object which holds the control of the Model and View of the classes. Controller gets input from the View and supplies a part of the Model and View’s functionality is assigned to the Controller to divide the work, but at the same time it increases the cohesion and decreases the coupling of the class by operating in a structured manner [3]. Controller component is an example of the indirection pattern since it is separated from the Model and View of the class. MVC hence is an indirection pattern as data from the main class is logically decoupled into a whole new structure called Controller, when at the same time it maintains the relation between the data in the class. Although the cohesion of the Controller with the Model and the View is high, Controllers can be modeled entirely independent of the View and the Model of the class [3]. Thus, Indirection patterns help in decomposing the system into independent modules while maintaining the logical flow and cohesion of the system.
 
The indirection pattern is a pattern that has been used in the GRASP [3]. GRASP stands for General Responsibility Assignment Software Patterns. GRASP principles list the guidelines for efficient object-oriented programming. Indirection pattern is essentially used to separate the entities in a class that are logically bound to each other into simpler entities, so as to divide the work done by the class. At the same time it is ensured that the cohesion of the data resources that have been broken into simple pieces remains high [3].  
 
 
A very good example which implements the Indirection pattern is the Model-View-Controller pattern, where there are two components namely the Model and the View for every class. The Model represents the data of the class and the View denotes the representation of the class when a user interacts with the class. The Controller component is the intermediate object which holds the control of the Model and View of the classes. Controller gets input from the View and supplies a part of the Model and View’s functionality is assigned to the Controller to divide the work, but at the same time it increases the cohesion and decreases the coupling of the class by operating in a structured manner [3]. Controller component is an example of the indirection pattern since it is separated from the Model and View of the class. MVC hence is an indirection pattern as data from the main class is logically decoupled into a whole new structure called Controller, when at the same time it maintains the relation between the data in the class. Although the cohesion of the Controller with the Model and the View is high, Controllers can be modeled entirely independent of the View and the Model of the class [3]. Thus, Indirection patterns help in decomposing the system into independent modules while maintaining the logical flow and cohesion of the system.




Line 18: Line 22:


  [[Image:ch7ttExamplesecond_img.png]]
  [[Image:ch7ttExamplesecond_img.png]]


== '''Context''' ==
== '''Context''' ==


The context of using an indirection pattern is when the data in the class has to be stored explicitly outside the class so as to offer more flexibility for developing an application. This way of developing applications provides an easier way of changing a part of the application without entirely modifying the application as each part acts as an independent entity by itself. Separation of data from application is done because data exists longer than the actual application in itself [3]. Hence, it is highly necessary to have a consistent definition of data to manage the data over a period of time.
The context of using an indirection pattern is when the data in the class has to be stored explicitly outside the class so as to offer more flexibility for developing an application. This way of developing applications provides an easier way of changing a part of the application without entirely modifying the application as each part acts as an independent entity by itself. Separation of data from application is done because data exists longer than the actual application in itself [3]. Hence, it is highly necessary to have a consistent definition of data to manage the data over a period of time.


== '''Problem''' ==
== '''Problem''' ==
Line 36: Line 42:


4) Addition of newer resources would not cause any change to the application [3].
4) Addition of newer resources would not cause any change to the application [3].


== '''Solution''' ==
== '''Solution''' ==
Line 53: Line 60:


  [[Image:ch7ttSolutionfirst_img.png]]
  [[Image:ch7ttSolutionfirst_img.png]]


== '''Advantages of Indirection pattern''' ==
== '''Advantages of Indirection pattern''' ==
Line 75: Line 83:


10) Scalability
10) Scalability


== '''Disadvantages of using Indirection pattern''' ==
== '''Disadvantages of using Indirection pattern''' ==


1) Additional overhead of storing the indirection table.
1) Additional overhead of storing the indirection table.
2) Greater algorithmic complexity to deal with due to the mapping required to the resource table to fetch the appropriate resource needed by the application for every run of the application [3].
 
3) Maintenance of the indirection table makes it more costly as the keys have to be constantly updated and the references should be constantly checked to verify if the point to the correctly updated resources [3].
2) Greater algorithmic complexity to deal with due to the mapping required to the resource table to fetch the appropriate resource needed by the application for every run of the application [3].
4) The resources have to be structured in a similar manner so as to ensure ex-changeability. This adds further constraints on the way the resources can be added since it has to strictly adhere to the rules with which the structure of the data resources were initially formed [3].
 
5) Dynamic binding of data resources with the application is often not taken care of in a structured manner
3) Maintenance of the indirection table makes it more costly as the keys have to be constantly updated and the references should be constantly checked to verify if the point to the correctly updated resources [3].
 
4) The resources have to be structured in a similar manner so as to ensure ex-changeability. This adds further constraints on the way the resources can be added since it has to strictly adhere to the rules with which the structure of the data resources were initially formed [3].
 
5) Dynamic binding of data resources with the application is often not taken care of in a structured manner
 


== '''Comparison with Abstraction concept''' ==
== '''Comparison with Abstraction concept''' ==
Line 88: Line 102:


Indirection pattern is often confused for abstraction concept in Object-oriented concepts. Abstraction essentially means hiding the complexity of the working of the overall architecture of the system, whereas Indirection means allocation or delegating a part of the functionality to another controller. The abstraction concept deals with hiding the implementation, while the indirection pattern carves off a portion of the responsibility of the main class to another controller, which will interact with the user-interface separately.  Indirect access of an indirection pattern class can be had to an abstraction layer without the knowledge of the actual implementation of the abstraction [6].
Indirection pattern is often confused for abstraction concept in Object-oriented concepts. Abstraction essentially means hiding the complexity of the working of the overall architecture of the system, whereas Indirection means allocation or delegating a part of the functionality to another controller. The abstraction concept deals with hiding the implementation, while the indirection pattern carves off a portion of the responsibility of the main class to another controller, which will interact with the user-interface separately.  Indirect access of an indirection pattern class can be had to an abstraction layer without the knowledge of the actual implementation of the abstraction [6].


== '''Conclusion''' ==
== '''Conclusion''' ==


The basic principle of the indirection pattern is to separate responsibility, provide for loose coupling and to allow for easy scalability. The pattern is closely aligned with MVC, which many consider a framework or architecture rather than a pattern. Other similar patterns all have the same benefits.
The basic principle of the indirection pattern is to separate responsibility, provide for loose coupling and to allow for easy scalability. The pattern is closely aligned with MVC, which many consider a framework or architecture rather than a pattern. Other similar patterns all have the same benefits.


== '''References''' ==
== '''References''' ==




References
 
[1] http://en.wikipedia.org/wiki/Indirection
[1] http://en.wikipedia.org/wiki/Indirection



Latest revision as of 03:02, 2 December 2010

Indirection pattern

The indirection pattern is used when data should not be a part of a class but rather contained within its own module. Additionally, indirection is a pattern when 2 or more modules do not interact directly but allow for a separate module to communicate between them. The ultimate result is loose coupling. Similar GRASP patterns are Proxy, Delegation, Bridge and Mediator [1, 2].


The indirection pattern is a pattern that has been used in the GRASP [3]. GRASP stands for General Responsibility Assignment Software Patterns. GRASP principles list the guidelines for efficient object-oriented programming. Indirection pattern is essentially used to separate the entities in a class that are logically bound to each other into simpler entities, so as to divide the work done by the class. At the same time it is ensured that the cohesion of the data resources that have been broken into simple pieces remains high [3].


A very good example which implements the Indirection pattern is the Model-View-Controller pattern, where there are two components namely the Model and the View for every class. The Model represents the data of the class and the View denotes the representation of the class when a user interacts with the class. The Controller component is the intermediate object which holds the control of the Model and View of the classes. Controller gets input from the View and supplies a part of the Model and View’s functionality is assigned to the Controller to divide the work, but at the same time it increases the cohesion and decreases the coupling of the class by operating in a structured manner [3]. Controller component is an example of the indirection pattern since it is separated from the Model and View of the class. MVC hence is an indirection pattern as data from the main class is logically decoupled into a whole new structure called Controller, when at the same time it maintains the relation between the data in the class. Although the cohesion of the Controller with the Model and the View is high, Controllers can be modeled entirely independent of the View and the Model of the class [3]. Thus, Indirection patterns help in decomposing the system into independent modules while maintaining the logical flow and cohesion of the system.


Example

An example that implements indirection is the Model-View-Controller (MVC) pattern. The Model represents the data, the View represents how a user interacts with the data and the Controller is the intermediate object that controls the Model and View classes and their interactions [4]. The Model is independent of both the View and Controller. The View interacts with the Model by reading data and receiving data updates. The Controller is responsible for updating the Model when required either because of user inputs or system events. In this example, the Controller is an intermediate entity that works between the data and the View forming an indirect pattern[5].


Database Example

Another example is a system that creates two different reports of business logic data. One view is for the customer service department and the other view is for the accounting department. The data extracted from the database is virtually the same but the reports generated are organized differently. The GUI controls which report the user sees and which data can be manipulated. If the data were bound with the report, the data would have to be called each time a different report is required. The diagram below shows the extracted data, which is completely independent of the reports and the GUI [5].

Other examples where Indirection patterns could be used are when a user needs a software application which would support multi-lingual text and operate independently of the language-related data. The display function required in different devices such as PC, PDA and other electronic devices needn’t be developed separately. Instead indirection pattern could be used to develop a common display application for all the electronic devices [3].



Context

The context of using an indirection pattern is when the data in the class has to be stored explicitly outside the class so as to offer more flexibility for developing an application. This way of developing applications provides an easier way of changing a part of the application without entirely modifying the application as each part acts as an independent entity by itself. Separation of data from application is done because data exists longer than the actual application in itself [3]. Hence, it is highly necessary to have a consistent definition of data to manage the data over a period of time.


Problem

The problem which the indirection pattern solves is lower the coupling factor of the application from its resources while still maintaining the relation between the two. There is always the possibility that different variations of the same resource need to be stored and the right resource has to be chosen based on the required configuration. This can be easily solved using the indirection pattern to choose which configuration best suited the required problem and apply the relevant resources to the current problem in hand to obtain the solution to the problem.

The Indirection pattern will attempt to solve the following problems:

1) The resources should be separated and independent of the software applications, so as to easily choose which resource needs to be applied for the specific application. The data resources needed to run the application can be chosen contextually based on the requirement of the specific application [3].

2) Any type of data resource can be used to run the application without any modification to the type of the data resource. The type of data resource signifies the different types of the data resource existing for the particular application. For instance, the different languages can be provided as data resource to the application to get specific outputs based on the specific language used as the input [3].

3) The application will run independent of the data resources as there will be low coupling between the resources and the application.

4) Addition of newer resources would not cause any change to the application [3].


Solution

In order to achieve indirection the following steps have to be followed:

1) Add an indirection table between the application and resources such that the application table maps the required resources based on the option chosen in the indirection table [3]

2) The option maps the resources which have been separated into a resource table to the application

3) Indirection table maintains a pointer or reference to the address of all the resources [3].

4) Keys are used to refer to a particular resource value in the resource table

5) An algorithm is implemented that would look up the right resource based on the option chosen by the user in the indirection table [3].




Advantages of Indirection pattern

1) Resources can be added as and when necessary without changing the structure of the application

2) Well-delineated separation between the resources and the application, making it easier to manage the data resources over a period of time [3].

3) Lack of dependency between the application and resources makes it lesser cost of maintenance of resources.

4) Higher decoupling of the resources from the application makes updating and changing the data resources more flexible and easy in the application [3].

5) The application needn’t be modified in any case as it operates independently of its data resources. The only change that would be required to in case of addition of newer resources would be in the indirection table and the corresponding options needed to point to the resource table [3].

6) The data can be used with any object

7) The interface can be changed without disturbing the data

8) Multiple views of the data can be created for a variety of purposes

9) Separation of Responsibility [4]

10) Scalability


Disadvantages of using Indirection pattern

1) Additional overhead of storing the indirection table.

2) Greater algorithmic complexity to deal with due to the mapping required to the resource table to fetch the appropriate resource needed by the application for every run of the application [3].

3) Maintenance of the indirection table makes it more costly as the keys have to be constantly updated and the references should be constantly checked to verify if the point to the correctly updated resources [3].

4) The resources have to be structured in a similar manner so as to ensure ex-changeability. This adds further constraints on the way the resources can be added since it has to strictly adhere to the rules with which the structure of the data resources were initially formed [3].

5) Dynamic binding of data resources with the application is often not taken care of in a structured manner


Comparison with Abstraction concept

Indirection pattern is often confused for abstraction concept in Object-oriented concepts. Abstraction essentially means hiding the complexity of the working of the overall architecture of the system, whereas Indirection means allocation or delegating a part of the functionality to another controller. The abstraction concept deals with hiding the implementation, while the indirection pattern carves off a portion of the responsibility of the main class to another controller, which will interact with the user-interface separately. Indirect access of an indirection pattern class can be had to an abstraction layer without the knowledge of the actual implementation of the abstraction [6].


Conclusion

The basic principle of the indirection pattern is to separate responsibility, provide for loose coupling and to allow for easy scalability. The pattern is closely aligned with MVC, which many consider a framework or architecture rather than a pattern. Other similar patterns all have the same benefits.


References

[1] http://en.wikipedia.org/wiki/Indirection

[2] Larman, Craig. Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development

[3] http://hillside.net/europlop/europlop2007/workshops/D1.pdf

[4] Skrien, Dale. Object-Oriented Design Using Java

[5] Lott, Joey and Patterson, Danny. Advanced ActionScript 3 with Design Patterns

[6] http://www.csci.csusb.edu/dick/samples/patterns.html