Saturday, May 16, 2009

Inheritance Feature in Oracle ADF BC - Part 2

My today post is second post that describes inheritance functionality support in ADF BC. I will describe how you can use inheritance in View Objects. In previous post I was describing inheritance in Entity Objects - Inheritance Feature in Oracle ADF BC Part 1. Inheritance on View Object layer adds more object abstraction, you can operate not only different sets of data based on discriminator, but implement polymorphism for View Row classes. For more information, you can read 35.7.5 Working with Polymorphic Rows section from ADF Developer Guide.

I have developed sample application - ADFBCInheritance2.zip, based on application from previous post - ADFBCInheritance.zip. Updated sample contains additional View Objects, extended from Country. Those new View Objects are CountriesAfricaView and CountriesEuropeView:


In the View Row class of CountriesView, I have defined calculateProfit method. This method will be overridden in extended View Objects:


I will create only two overridden View Objects from possible four - for Africa and Europe discriminator values. CountriesAfricaView inherits calculateProfit method:


And CountriesEuropeView inherits same calculateProfit method:


I have defined Row Class for both extended View Objects, in those classes I'm overriding calculateProfit method from parent Row Class of CountryView:


For example, in CountriesEuropeViewRowImpl class I'm setting profit value to 500, while in CountriesAfricaViewRowImpl class to 200 and finally in CountriesViewRowImpl to 700. This means rows that belong to Asia and America discriminator value, will get 700 value for Profit attribute:


Last step, when enabling inheritance in View Objects layer, you need to set Subtypes in Application Module for polymorphic View Object - CountriesView in our case:


Press Subtypes button and and choose available View Object that extends parent:


In View layer, from Backing Bean, I'm scrolling through all rows from CountriesView and invoking calculateProfit method. Through implemented polymorphism, this method will be invoked for specific row based on its discriminator type, we dont need to specify it directly:


During runtime, I will invoke method from Backing Bean, by pressing Set Profit button:


To test that polymorphism really works, go to Europe section and check that Profit value is set to 500, as it was specified in overridden method:


Then go to Asia section, and check that Profit is set to 700, as it was specified in the Row Class of parent CountriesView:


Spanish Summary:

El post anterior, mostró como aplicar el concepto de Herencia en las Entidades. Sin embargo el mismo principio puede ser aplicacion a los componentes View Object. En este post, Andrejus nos muestrá, de manera práctica como aplicar herencia entre Vistas.

No comments: