View RSS Feed

Recent Blogs Posts

  1. Class Registration - using reflection

    by , 03-09-2012 at 08:11 PM
    Registration of the new product class could be done to the factory in case you use reflection (e.g in .NET languages or Java), without making any change in factory itself.Without being aware of the object type for creation of the objects in factory class, a map is kept b/w class type and productID. In this particular case, when new product gets added to the application then it shall be made registered to factory. No change is required in factory class code for this kind of operation.
  2. Reflection example - accessing private data

    by , 05-21-2011 at 06:28 PM (My Java Tips)
    If you think that you cannot access private data members of a class from some other class, then think again. With Reflection, this is possible.

    Using reflection, we can see / view / access a private member, private variable, private method. Some people will not like this with argument that this actually means messing up the laws of encapsulation. I use it for unit testing private methods.

    Example follows:

    Java Code:
    import java.lang.reflect.Field;
    Tags: reflection Add / Edit Tags
    Java SE