CSC/ECE 517 Fall 2012/ch2b 2w39 ka: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 85: Line 85:


|-
|-
! Comparison
! Decorator
! Decorator
! Adapter
! Adapter
Line 92: Line 93:
|-
|-
| Supports abc
| Supports abc
| Supports def
|
| Supports ghi
|  
| Supports bla
|  


|-
|-
|  
| Supports def
|  
|  
|  
|  
Line 103: Line 104:


|-
|-
|  
| Supports ghi
|  
|  
|  
|  
Line 109: Line 110:


|-
|-
|  
| Supports bla
|  
|  
|  
|  
Line 115: Line 116:


|-
|-
|  
| Supports bla
|  
|  
|  
|  

Revision as of 22:29, 16 November 2012

Introduction

Describe what Design pattern is and what are we going to discuss in this article.

Decorator Pattern

brief overview

Intent

Problem

Solution

Example

Implementation

Ruby

brief explanation and Sample Code:

     type the code here

Java

brief explanation and Sample Code:

     type the code here

Adapter Pattern

brief overview

Intent

Problem

Solution

Example

Implementation

Ruby

brief explanation and Sample Code:

     type the code here

Java

brief explanation and Sample Code:

     type the code here

Proxy Pattern

brief overview

Intent

Problem

Solution

Example

Implementation

Ruby

brief explanation and Sample Code:

     type the code here

Java

brief explanation and Sample Code:

     type the code here

Composite Pattern

brief overview

Intent

Problem

Solution

Example

Implementation

Ruby

brief explanation and Sample Code:

     type the code here

Java

brief explanation and Sample Code:

     type the code here
Comparison Decorator Adapter Proxy Composite
Supports abc
Supports def
Supports ghi
Supports bla
Supports bla

Applications of Reflection

  • Reflection has become invaluable to programmers who need to connect code with data. For example in a GUI environment, a button might need to invoke different methods in different classes. Reflection can be used here to call the method on any given class.
  • Programmers who deal with a multitude of classes at the same time can use reflection to create a serializer that for a given class uses reflection to go through all the instance variables and processes them accordingly.
  • Reflection is used in large test frameworks where reflection helps in identifying the test methods for different scenarios.
  • Reflection can be used to debug and verify code as it provides access to the insides of a program.
  • Reflection is very useful when the software is upgraded regularly. It provides an easy method to check for available methods and classes. This prevents the errors caused by the absence of methods and classes when they are deprecated.

Advantages and disadvantages of reflection

Advantages

  • Extensibility: Reflection provides the capability of using external and user defined classes by instantiation of extensibility objects using their fully qualified names.
  • Class browsers in IDEs: The ability to examine the members of classes makes implementation of visual aids , auto-completion and documentation easy in development tools for programmers.
  • Debugging: Reflection allows the user to observe the private members in classes. This capability can be used to debug classes and their interactions.
  • Test Harness: Reflection can be used to call a set of testing APIs defined on a class for maximum coverage of testing.
  • Correctness : Reflection improves the robustness and the correctness of a program especially in dynamically typed languages as run time checks can be added to check the availability of the methods or classes.

Disadvantages

  • Reflection introduces lot of performance overhead when compared to non-reflective code. Hence it should be used judiciously.
  • Since it provides access to the internals of a class or an encapsulated object security becomes a major issue.
  • Since it is run-time binding we lose the security of compile time checks and verification <ref>Analysis of Programming Languages</ref>

Conclusion

This article makes an attempt to explain the concept of Reflection in Object Oriented Programming. The article mentions the different approaches to reflection in Ruby and other languages.It mentions the usage of Reflections and the advantages and disadvantages of using Reflection. A follow up to this article would be to study the concept of Metaprogramming.

References

<references />

Additional Reading