Sunday, April 25, 2010

Framework Extension Classes

Idea behind doing extending classes

One of the benefits of working with a framework is the ability to extend the framework classes to get a built in feature to work differently or enhanced / enrich its behaviour and utilise it all across the application.
- To augument a built in feature
- change how a built in feature works
- workaround a bug in the built in feature

Extending the class is pretty straightforward. Just create a new class and use extends keyword to make it extend the old class.

Including extended classes:
you can created extended classes in a separate project. If you have done that then you would have to include the project which contains the extended classes as a dependency of you project. Go to dependencies property in your project properties and add the extended claasses project in there.

if you have packaged the extended classes in a JAR file then create a named library definition to reference the JAR file and also list the library in library list of the project where you need these extended classes.

Getting ADF components to use the extended classes: For each ADF component there is a java page on the wizard. Here you can choose the base class that you want to extend and create an extended classes that can be used by the component.

Multiple levels of extension classes. In practice there can be and probably will be multiple levels of extension classes which are created for a an application. Some generic functionality is added or altered at the application level and hence an ApplicationCustomAppModuleImpl is created. Furthere there may be a need to add or alter some features at the project level. So ProjectCustomAppModuleImpl will extend ApplicationCustomAppModuleImpl. And at the application module level MyAMAppModuleImpl will extend ProjectCustomAppModuleImpl.

By default defining fwk extension classes for all new components: If you want to use a specific set of base classes upon which the custom classes for your project components should be based then you can define it in project properties > business components > base classes
You can also specify the extension classes for all new projects by going to Tools > Preferences > business components > base classes


Its always a good idea to create customised extension classes for your project or application at the very beginning. As you start writing you very first lines of code you might not have a need for any generic code. Nor you may fathom a requirement in the future. But quite frequently as the application begins to take shape you will come across bits and pieces that you would think can be shared across you various code components. By then it would involve a lot of effort to extend all you existing classes on a new class. So its a good idea to create a set of custom extension classes right at the beginning and add code to them as and when required.

A common set of customized framework base classes in a package name of your own choosing like com.yourcompany.adfextensions, each importing the oracle.jbo.server.* package, would consist of the following classes:
- public class CustomEntityImpl extends EntityImpl
- public class CustomEntityDefImpl extends EntityDefImpl
- public class CustomViewObjectImpl extends ViewObjectImpl
- public class CustomViewRowImpl extends ViewRowImpl
- public class CustomApplicationModuleImpl extends ApplicationModuleImpl
- public class CustomDBTransactionImpl extends DBTransactionImpl2
- public class CustomDatabaseTransactionFactory extends DatabaseTransactionFactory
For completeness, you may also want to create customized framework classes for the following classes as well, note however that overriding anything in these classes would be a fairly rare requirement.
- public class CustomViewDefImpl extends ViewDefImpl
- public class CustomEntityCache extends EntityCache
- public class CustomApplicationModuleDefImpl extends ApplicationModuleDefImpl

It is best to package these framework extension class in a JAR file so that they can be used across projects and applications.
Named libraries are a convenient way to use these JAR files in your code.


Reference:
http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcadvgen.htm#insertedID0

No comments:

Post a Comment