Skip to content

hariram1981/DynamicFactory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DynamicFactory

Class that implements factory pattern dynamically (dynamically creating classes using reflection). Take a look at the JUnit test case that has been written as to usage.

Classes

###1. com.hariram.factory.DynamicFactory

  • Class that handles factories in dynamic.

####Data Members

  1. List types - types of classes that are created by the factory.
  2. Class returnClassName - the class or interface that is returned back after factory has created objects.

####Member functions

  1. void setReturnClassName(Class<? extends Object)
  • Sets the class that is returned after factory creation.
  1. void setTypes(List)
  • Sets the list of types that are supported for factory creation.
  1. Class<? extends Object> getReturnClassName
  • Returns the class that is returned (as generic) after factory creation.
  1. List getTypes()
  • Returns the list of types that are supported for factory creation.
  1. Object getObject(String)
  • Implements factory pattern and creation returns the generic class for the type passed.
  • Before this method is used, the types that are available for creation and the generic that is returned after creation have to be set using setTypes and setReturnClassName OR using the parameterized constructor.
  1. DynamicFactory(List, Class<? extends Object)
  • parameterized constructor that sets the names of the types of objects that are created by factory and the return class.

Usage

  • Usage can be checked in the JUnit test case that has been written for it but below is a sample:

      List<String> types = Arrays.asList("DB", "File");
      DynamicFactory factory = new DynamicFactory(types, Connection.class);
      Object obj = factory.getObject("DB");
      System.out.println(obj instanceof Connection);
    
  • In above, Connection is the return class and the objects created are DBConnection and FileConnection. Hence the types of connection classes to be created by factory are "DB" and "File".

License

Copyright (c) 2014 GitHub, Inc. See the LICENSE file for license rights and limitations (GNU GPL v2.0)

About

Factory class that is dynamic in nature

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages