Regarding polymorphism
Hi
I have doubt regarding polymorphism.Why we are calling oveloading is
compiletime polymorphism and overridding is called runtime polymorphism.
satishnarayan wrote:
Hi
I have doubt regarding polymorphism.Why we are calling oveloading is
compiletime polymorphism and overridding is called runtime polymorphism.Because with overloading, the compiler knows exactly which method signature will be called, but with overriding, it's the JVM--the runtime environment--that discovers which class' version of the method will be called.
public class Parent {
// overloading
public void foo(Object obj) { System.out.println("obj"); }
public void foo(String str) { System.out.println("str"); }
// overriding
public void bar() { System.out.println("parent"); }
public class Child extends Parent {
public void bar() { System.out.println("child"); }
Object obj1 = new Object(); // compiler only knows obj1 Object reference, not new Object()
Object obj2 = "abc"; // compiler only knows obj2 Object reference, not that the object it points to at runtime will be a String
String str = "xyz"; // compiler only knows String reference type for str variable
Parent p1 = new Parent();
p1.foo(obj1); // "obj"
p1.foo(obj2); // "obj"
p1.foo(str); // "str"
Parent p2 = new Child();
Child c = new Child();
p1.bar(); // "Parent"
p2.bar(); // "Child"
c.bar(); // "Child"The compiler knows the type of the reference, but it doesn't know the class of the object that reference will point to at runtime. p2 = new Child(); could have been replaced with a method that randomly returns a Parent, a Child, or any other subclass of Parent. Whose version of the bar() method gets called is determined by what that runtime object is.
With overloading, it doesn't matter what the runtime class of the object is. Which signature gets called is entirely determined by the compile-time types of the parameter references.
Similar Messages
-
Question regarding Polymorphic VIs
Let's use Read Key as an example (from the Configuration File VIs).
I want to wrap Read Key (which is Polymorphic) so that some other code always runs right before Read Key. However, to do this, it seems I have to make an instance of the wrapper VI for each output type that Read Key supports if I want it to support all the types. This is disappointing since in C++ or Java you'd just use a template or generic and you wouldn't need to do all this extra work. Is there a way around this when working with Polymorphic VIs?
The alternative is to always remember to put this code right before Read Key. Another less than optimal solution. If I want tightly connected and cohesive code, I want one VI and not a half dozen of them!
Anyways, this is almost certainly not possible so I guess this is more of a complaint haha.
Solved!
Go to Solution.Vote up this idea in the LabVIEW Idea Exchange:http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Provide-a-better-way-to-implement-a-polymorphic-VI/idi...
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Hi all,
I have a question regarding Polymorphism in Java Inheritance.
Consider the following
public class Parent {
void doSomethingParent() {
System.out.println("P");
public class Child1 extends Parent{
void doSomethingChild1() {
void doSomethingParent() {
System.out.println("Child1");
public class Child2 extends Parent{
void doSomethingChild2() {
void doSomethingParent() {
System.out.println("Child2");
public class TestClass {
public static void main(String[] args) {
Parent p = new Child1();
p.doSomethingParent(); //1
p.doSomethingChild1(); //2
}In line 2 in TestClass above, I get a compilation error "doSomethingChild1() is undefined for Parent class"
At compile time, the compiler knows that the reference variable 'p' points to a Child1 object. Why does it then, not allow us to call the methods that belong to Child1.
Please let me know the answer to this, i am really very curious.
Thanks!!fiona_016 wrote:
But when it knows for sure that p points to a Child1 object...In many cases, the compiler does not know for sure. For instance, if your p variable would be a class variable, another thread may change it from being a Child1 to being a Child2 in between the declaration and the call. Even without multithreading, suppose p is assigned in another method (in another class maybe). Should the compiler try to analyse the code as far as possible to infer the actual type of p? I don't think so. This would introduce inconsistencies in the language and it will be hard to discern (for the programmer) when such inference should or should not take place. The way it is, it's consistent, simple and, I would say, safe. Safe=the compiler tells you that the code needs to be fixed, either by changing the variable type or by not calling that method. The non-compilable code may hide a logic error. -
hi
I've got a question regarding polymorphism in java:
public class Test1 {
public Test1() {
Test3 t3=new Test2();
t3.output();
t3.value1=9; //not possible
public static void main(String[] args) {
new Test1();
public class Test2 extends Test3 {
public int value1=5;
@Override
public void output() {
System.out.println("the value is "+value1);
public class Test3 {
public void output(){
System.out.println("class: Test3");
output of the program:
the value is 5why do i have no access from "Test1" to the member variable "value1" which is initialized in class "Test2" although i'm calling the constructor "Test2()"?
and why is the output of the program "the value is 5" although I've got no access to "value1" from "Test1" like i said before?becky3 wrote:
why do i have no access from "Test1" to the member variable "value1" which is initialized in class "Test2" although i'm calling the constructor "Test2()"?Because the type of t3 is reference to Test3, and Test3 does not have a value1 variable. The compiler doesn't know that at runtime that reference is going to point to a subclass of Test3 that does have that variable.
and why is the output of the program "the value is 5" although I've got no access to "value1" from "Test1" like i said before?Because that's how Java's runtime polymorphism works. When you call an overridden method, it's the runtime class of the object that determines whose version of that method gets called. Since the object is a Test2, it's Test2's implementation of the method that gets called. The caller and type of reference don't have to know about the internal details of that class. Only that it's a subclass of Test3, and therefore exposes all the same public instance members as Test3. -
How to create ADF UI based on polymorphic view objects
Hi,
I'm using JDeveloper build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660. I created a simple application based on Steve's example #10 [url http://blogs.oracle.com/smuenchadf/examples/]ViewRow and EntityObject Polymorphism.
I added a men-only attribute "Age" to the "Men" VO and filled it with an arbitrary value in MenRowImpl.java:
public String getAge() {
return (String) "45";//getAttributeInternal(AGE);
}Running the TestModule works perfectly - a row of type "Men" displays the "Age" attribute whereas a row of type "Women" doesn't.
Afterwards, I setup an ADF ViewController Project and created a JSPX with a read-only form based on the "People" datacontrol with navigation buttons. Running that page always shows the same set of attributes independent of the row type. That's expected behaviour because the binding is defined at design time.
So my question is: can I somehow achieve the same behaviour for polymorphic VOs as the business component tester shows?
Kind regards,
MarkusAndrejus' example shows how to calculate different values for the same attribute based on overridden view objects. That's not exactly what I'm looking for. I need to display a (at least partly) different set of attributes that changes while the user scrolls through the records of the result set.
-
ADF BC : polymorphic activation issue
hi
Please consider this example application created using JDeveloper 10.1.3.4.0
at http://www.consideringred.com/files/oracle/2010/PolymorphicActivationIssue10gApp-v0.01.zip
It has Entity Objects AdPresEmployees and ItProgEmployees that extend the Employees Entity Object (based on HR.EMPLOYEES).
There is also the View Object EmployeesVO that is based on Employees and its sub-types AdPresEmployees and ItProgEmployees.
The basic scenario (sc1) for the expected behaviour goes like
- (sc1-a) run createEmployees.jspx
- (sc1-b) enter "20" for "create_pEmployeeId" and "20email" for "create_pEmail" and click the "createAdPresEmployees" button, resulting in a new AdPresEmployeesImpl based row in the table
- (sc1-c) enter "21" for "create_pEmployeeId" and "21email" for "create_pEmail" and click the "createItProgEmployees" button, resulting in a new ItProgEmployeesImpl based row in the table
To reproduce scenario (sc1) it is important to not have the system property "jbo.ampool.doampooling" configured to get the default Application Module pooling behaviour, and to have "-Ddopolymorphicactivationfix=false" (or not configured), to result in two new rows in the table as can be seen in the screenshot PAI-sc1-doPooling-noFix.png.
To reproduce the problem in a scenario (sc2) with the same steps as (sc1) but with "-Djbo.ampool.doampooling=false" configured to avoid Application Module pooling and force passivation and activation, still "-Ddopolymorphicactivationfix=false", the result for a step (sc2-c) would be "JBO-27027: Missing mandatory attributes for a row with key ..." and several "JBO-27014: Attribute ... is required" messages as can be seen in the screenshot PAI-sc2-noPooling-noFix.png.
Maybe the problem in scenario (sc2) is related to bug 9495116, "PROBLEM WITH ACTIVATION PASSIVATION MAKING USE OF POLYMORPHISM ENTITIES ...".
After some debugging, to try and work around this problem I have overridden the method findByPrimaryKey() in a custom Entity Definition class like this, conditionally calling findByPKExtended()
public class EmployeesDefImpl
extends EntityDefImpl
public EntityImpl findByPrimaryKey(DBTransaction pDBTransaction, Key pKey)
if ("true".equals(System.getProperty("dopolymorphicactivationfix"))
&& isCalledFromActivateNewRowTrackerMethod())
return super.findByPKExtended(pDBTransaction, pKey, true);
return super.findByPrimaryKey(pDBTransaction, pKey);
}So, a scenario (sc3) similar to (sc1) with default Application Module pooling but with "-Ddopolymorphicactivationfix=true" still behaves the same as (sc1), resulting in two new rows in the table as can be seen in the screenshot PAI-sc3-doPooling-doFix.png.
But, also a scenario (sc4) with "-Djbo.ampool.doampooling=false", so no pooling, and "-Ddopolymorphicactivationfix=true", now behaves as expected, see screenshot PAI-sc4-noPooling-doFix.png.
questions:
- (q1) Is there a real solution for the polymorphic activation problem in scenario (sc2)?
- (q2) Is the workaround in scenario (sc4) a valid workaround, or how can it be improved?
many thanks
Jan Verveckenfyi
This looks like it could be related to the blog post from Dimitrios Stassinopoulos, "Entity Inheritance And Passivation-Activation Possible Problem in ADF 11g ",
at http://dstas.blogspot.com/2010/11/entity-inheritance-and-passivation.html
regards
Jan -
Trim Whitespace.vi - remove unused polymorphic VI instances
Hello All
From some time while building the exe file I have started to receive the error:
Error 1073 occurred at E:\Program Files\National Instruments\LabVIEW 7.1\vi.lib\Utility\error.llb\Trim Whitespace.vi
Possible reason(s):
Application Builder: Unable to disconnect type definitions and remove unused polymorphic VI instances for this application. Deselect this option on the Application Settings tab and build the application again.
It did not happen before. Of course I can leave all polymorphic vis in my application, but why I started to get this error? It never happened before. Especially that the Trim Whitespace.vi is not a polymirfic vi.
Any ideas?
thanks in advance.
PawelHi Mohadjer
Demn.... I remember now. I started to get this error when I saved my vi (for other purposes) with removed diagrams. Probably it removed it also from the vi.lib vis. Wow.... Now I am having problems, how many vis I have destroyed when this happened.
Anyways, thanks a lot for this. At least I know what I have done .
regards
Pawel -
Possible bug in Polymorphi​c AI Single Scan?
I'm trying to use the AI Single Scan VI to read a set of 3 analog input
channels (2 differential, 1 rse) under LabView 6i, but I'm having some
strange problems. The output is polymorphic, so I select the output type I
want by popping up and going to "Select Type" and picking the output style
I'm looking for.
Here's the problem: I cannot get the Single Scan to reliable return Scaled
& Binary data at the same time! Either "Scaled" or "Binary" mode works, but
when I select "Scaled & Binary" it only returns data in one of the two
arrays--the other is left empty. What's more, the array which contains data
seems to depend on the _last_ way I had the VI configured (i.e. if I do
"Binary" and then "Scaled & Binary"
it returns the binary data but NOT the
scaled, while conversely if I start with "Scaled" and then select "Scaled &
Binary" it's the scaled data that gets returned properly.)
This looks to me like it might be a bug in LabView 6i. I haven't
exhaustively tested it, but what I'm doing isn't exactly complicated, and I
was able to do the same thing back in Labview 5.x.x with no difficulty. Is
there something I'm doing wrong?
Justin Goeres
Indio Systems, Inc.
Pleasanton, CAJustin,
This sounds like an issue that was reported in NI-DAQ 6.8. It has since been fixed in NI-DAQ 6.9. I would recommend updating your NI-DAQ driver and see if that fixes the problem. You can download NI-DAQ 6.9 from www.ni.com/softlib.nsf/. Hope this helps.
Regards,
Erin -
Help regarding ABAP and ABAP Objects
Dear all,
I am very new in abap and abap objects. But i have some expr. in other language..specialy development. Right now i am working for srm module...So i want to move my self into abap object and specialy in workflow...Please provide me help regarding this...along with the starting point for this.
Best Regards
Vijay Patilhi
Object Oriented prg
A programming technique in which solutions reflect real world objects
What are objects ?
An object is an instantiation of a class. E.g. If Animal is a class, A cat
can be an object of that class .
With respect to code, Object refers to a set of services ( methods /
attributes ) and can contain data
What are classes ?
A class defines the properties of an object. A class can be instantiated
as many number of times
Advantages of Object Orientated approach
Easier to understand when the system is complex
Easy to make changes
Encapsulation - Can restrict the visibility of the data ( Restrict the access to the data )
Polymorphism - Identically named methods behave differently in different classes
Inheritance - You can use an existing class to define a new class
Polymorphism and inheritance lead to code reuse
Have a look at these good links for OO ABAP-
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sap-img.com/
http://www.sapgenie.com/
http://help.sap.com
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com.
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
check the below links lot of info and examples r there
http://www.sapgenie.com/abap/OO/index.htm
http://www.geocities.com/victorav15/sapr3/abap_ood.html
http://www.brabandt.de/html/abap_oo.html
Check this cool weblog:
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sap-img.com/
http://www.sapgenie.com/
http://help.sap.com
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
these links
http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm
For funtion module to class
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm
for classes
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm
for methods
http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
for inheritance
http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm
for interfaces
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm
For Materials:
1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291
2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
8) http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
1) http://www.erpgenie.com/sap/abap/OO/index.htm
2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
Hope this helps
if it helped, you can acknowledge the same by rewarding
regards
ankit -
How to password protect a Polymorphic VI
Sir/madam,
I am working in a project which seems to have some polymorphic VI.So i need to password protect the polymorphic Vi .I need to know how to protect it.
Regards
Sathish
Soliton Technologies
Bangalore
India
91(80)41208600Open the VI and go to File>>VI Properties>>Security.
If you want to protect the actual VIs you will need to do this to every one of them.
Try to take over the world! -
Regarding (oops) Interface
hi,
could u plz tell me can we create instance for Interface,
if it is possible how?Hi Rajesh,
This program will show the use of interface reference variable and how it can be used to access the components of an interface in a class(implementing that interface). Use of interface reference variable paves the way for polymorphism via interface.
INTERFACE lif_employee
INTERFACE lif_employee.
METHODS:
add_employee
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i.
ENDINTERFACE.
Super class LCL_CompanyEmployees
CLASS lcl_company_employees DEFINITION.
PUBLIC SECTION.
INTERFACES lif_employee.
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
wage TYPE i,
END OF t_employee.
Declare event. Note that declaration could also be placed in the
interface
EVENTS: employee_added_to_list
EXPORTING value(ex_employee_name) TYPE string.
CLASS-EVENTS: Events can also be defined as class-events
METHODS:
constructor,
display_employee_list,
display_no_of_employees,
Declare event method
on_employee_added_to_list FOR EVENT
employee_added_to_list OF lcl_company_employees
IMPORTING ex_employee_name sender.
PRIVATE SECTION.
CLASS-DATA: i_employee_list TYPE TABLE OF t_employee,
no_of_employees TYPE i.
ENDCLASS.
*-- CLASS LCL_CompanyEmployees IMPLEMENTATION
CLASS lcl_company_employees IMPLEMENTATION.
METHOD constructor.
no_of_employees = no_of_employees + 1.
ENDMETHOD.
METHOD add_employee.
METHOD lif_employee~add_employee.
Adds a new employee to the list of employees
DATA: l_employee TYPE t_employee.
l_employee-no = im_no.
l_employee-name = im_name.
l_employee-wage = im_wage.
APPEND l_employee TO i_employee_list.
Raise event employee_added_to_list
RAISE EVENT employee_added_to_list
EXPORTING ex_employee_name = l_employee-name.
ENDMETHOD.
METHOD display_employee_list.
Displays all employees and there wage
DATA: l_employee TYPE t_employee.
WRITE: / 'List of Employees'.
LOOP AT i_employee_list INTO l_employee.
WRITE: / l_employee-no, l_employee-name, l_employee-wage.
ENDLOOP.
ENDMETHOD.
METHOD display_no_of_employees.
Displays total number of employees
SKIP 2.
WRITE: / 'Total number of employees:', no_of_employees.
ENDMETHOD.
METHOD on_employee_added_to_list.
Event method
WRITE: / 'Employee added to list', ex_employee_name.
ENDMETHOD.
ENDCLASS.
Sub class LCL_BlueCollar_Employee
CLASS lcl_bluecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_hours TYPE i
im_hourly_payment TYPE i,
add_employee REDEFINITION.
lif_employee~add_employee REDEFINITION..
PRIVATE SECTION.
DATA:no TYPE i,
name TYPE string,
hours TYPE i,
hourly_payment TYPE i.
ENDCLASS.
*---- CLASS LCL_BlueCollar_Employee IMPLEMENTATION
CLASS lcl_bluecollar_employee IMPLEMENTATION.
METHOD constructor.
The superclass constructor method must be called from the subclass
constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
hours = im_hours.
hourly_payment = im_hourly_payment.
ENDMETHOD.
METHOD add_employee.
METHOD lif_employee~add_employee.
Calculate wage an call the superclass method add_employee to add
the employee to the employee list
DATA: l_wage TYPE i.
l_wage = hours * hourly_payment.
CALL METHOD super->add_employee
CALL METHOD super->lif_employee~add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
Sub class LCL_WhiteCollar_Employee
CLASS lcl_whitecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_monthly_salary TYPE i
im_monthly_deductions TYPE i,
add_employee REDEFINITION.
lif_employee~add_employee REDEFINITION.
PRIVATE SECTION.
DATA:
no TYPE i,
name TYPE string,
monthly_salary TYPE i,
monthly_deductions TYPE i.
ENDCLASS.
*---- CLASS LCL_WhiteCollar_Employee IMPLEMENTATION
CLASS lcl_whitecollar_employee IMPLEMENTATION.
METHOD constructor.
The superclass constructor method must be called from the subclass
constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
monthly_salary = im_monthly_salary.
monthly_deductions = im_monthly_deductions.
ENDMETHOD.
METHOD add_employee.
METHOD lif_employee~add_employee.
Calculate wage an call the superclass method add_employee to add
the employee to the employee list
DATA: l_wage TYPE i.
l_wage = monthly_salary - monthly_deductions.
CALL METHOD super->add_employee
CALL METHOD super->lif_employee~add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
R E P O R T
DATA:
Object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
Create bluecollar employee obeject
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_hours = 38
im_hourly_payment = 75.
Register event for o_bluecollar_employee1
SET HANDLER o_bluecollar_employee1->on_employee_added_to_list
FOR o_bluecollar_employee1.
Add bluecollar employee to employee list
CALL METHOD o_bluecollar_employee1->add_employee
CALL METHOD o_bluecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
Create whitecollar employee obeject
CREATE OBJECT o_whitecollar_employee1
EXPORTING im_no = 2
im_name = 'John Dickens'
im_monthly_salary = 10000
im_monthly_deductions = 2500.
Register event for o_whitecollar_employee1
SET HANDLER o_whitecollar_employee1->on_employee_added_to_list
FOR o_whitecollar_employee1.
Add bluecollar employee to employee list
CALL METHOD o_whitecollar_employee1->add_employee
CALL METHOD o_whitecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'John Dickens'
im_wage = 0.
Display employee list and number of employees.
CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.
Reward Points, if useful.
Regards,
Manoj Kumar -
Polymorphism in a JAX-WS 2.1
I will try and describe this problem by using simple examples - I would like to leverage the power of polymorphism in web services. Suppose I have a simple web service class with a set and get operation as below:
package wsserv;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public class OptionService{
private OptionBean option = new OptionBean(1, "Default Value");
@WebMethod(operationName = "setOption")
@Oneway
public void setOption(@WebParam(name = "option") OptionBean option){
this.option = option;
@WebMethod(operationName = "getOption")
public OptionBean getOption(){
return option;
}And a simple bean to be accessible on the client and server, as below:
package wsserv;
import java.io.Serializable
public class OptionBean implements Serializable{
private int id;
private String label;
public OptionBean(){
public int getId()}{
return id;
public void setId(int id){
this.id = id;
public String getLabel(){
return label;
public void setLabel(String label){
this.label = label;
}Deploying this as a web services allows the client to use instances of the OptionBean class - no problems there. Now suppose I do the following
package wsserv;
public class DescribedBean extends OptionBean{
private String description;
public String getDescription(){
return description;
public void setDescription(String description){
this.description = description;
}OK, so this is my question: Is there any annotation I can place on this class to make it available to web service clients? If I define a method in the webservice:
@WebMethod(operationName = "setDescribed")
@Oneway
public void setDescribed(@WebParam(name = "described") DescribedBean described){
this.option = described;
}then I can use instances of DescribedBean in the setOption and getOption methods. Ideally though, I do not want to have to add methods to the web service for every subclass of OptionBean that arises.
If there is no such annotation, then is there a way to manually update the XML schema produced, so that I can add in required subclasses there?
Thank you in advance for any help you can provide.Try to use XmlSeeAlso annotation this way:
@XmlSeeAlso( value=DescribedBean.class )
public class OptionBean implements Serializable{
private int id;
private String label;
public OptionBean(){
public int getId()}{
return id;
public void setId(int id){
this.id = id;
public String getLabel(){
return label;
public void setLabel(String label){
this.label = label;
}I hope your version of JAXB supports it. If I remember correctly this annotation is available since JAXB 2.1.x
Regards,
Slawomir Wojtasiak -
Saving polymorphic vi as single file
Is there a way to save polymorphic VIs as single files? As far as I understood, the polimprphic VI is somehow a list of "links" to the different instances. Is there a way to include the instances on the "main" vi, and maybe access them via the polymorphic VI window?
ThanksHi xdaf,
I usually solve this issue by this procedure:
- I have my user.lib files in a different folder (in my local user path) and only edit the palette to include the VIs I need (This way it's much easier to backup all of my VIs.)
- I usually only put the polymorphic VI into the user.lib. All the single instances are located in a different folder and thus not seen in the user palette.
Disadvantage of this scheme:
When I install a new LV version I have to setup my user palette content again. Well, it's just 5 folders in the user palette...
Message Edited by GerdW on 01-28-2010 03:07 PM
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Polymorphism - retrieving type informati[Ref:C520982]
Hi Tim.
Just a few thoughts on your question, based on some of the work we've done here.
We use your solution (1) to deal with this type of problem. As an example we
deal with it:
We have class called Constraint, with several subclasses (eg. Permanent,
TimeBased, ) requiring different attributes.
They are all stored in the database table Constraint, with an additional column
for the class of constraint - we call this ConstraintType.
On reading from the database, we have a class called GenericConstraint which
contains all the attributes from all the subclasses and the ConstraintType
column. We read from the database into an array of GenericConstraint.
To convert GenericConstraint into the proper subclass, we instantiate the
correct class, determined by looking at the ConstraintType attribute, and then
calling it's create method, which takes a Generic Constraint parameter. (An
alternative would be to call a method on GenericConstraint which did something
similar and returned the correct class).
This works very well for us, as the GenericConstraint class and methods which
use it provide a nice interface between the class structure we use and the
database structure in the database, and therefore flexibility.
Looking at the pattern of nulls to determine which class to instantiate may be
much more restrictive. The separate table idea that you mentioned sounds like a
one-to-one relationship - is there much benefit in implementing this separately
and then having to join the additional table ?
Hope this helps.
Steve Elvin
Frontline Ltd.
UK.
-----Original Message-----
From: INTERNET [email protected]
Sent: Monday, June 15, 1998 12:29 PM
To: Stephanie Mahay; Steve Elvin; X400
p=NET;a=CWMAIL;c=GB;DDA:RFC-822=forte-users(a)sagesoln.com;
Subject: Polymorphism - retrieving type informati [Ref:C520982]
Suppose I have a class structure containing one base class with several speciali
sations. Say, "Vehicle", with specialisations of "Car", "Van" and "Truck". All v
ehicles are persisted in the database, in a rolled-up table, and I want a generi
c retrieval mechanism, which fetches a vehicle based on the license plate number
. (It will probably be a service object, which I will call a Persistent Object M
anager).
I wish to retrieve ALL vehicles, and calculate the road tax for each. However, c
ars, vans and trucks are all subject to different tax rules, and require a diffe
rent method to calculate their road tax. To put it another way, there is a polym
orphic method 'CalculateRoadTax' on the "Vehicle" class.
Q: As each vehicle is extracted from the database, how does the rest of the Fort
e application know what type of vehicle it is?
I am sure that others must have solved this problem before, but it is new to us.
We have come up with the following solutions:
(1) Add a "sub-type" column to the "Vehicle" table. Use the type information to
instantiate a Forte object of the correct type
(2) Maintain a completely separate table linking the vehicle licence plate to i
ts sub-type.
(3) Deduce the type of the object from the pattern of null columns in the row.
I think (1) is the best solution, but I'm interested to know what the experts sa
y!
Incidentally, if Express can help or hinder in this situation, I would be intere
sted in that as well.
regards,
Tim Kimber
EDS (UK)
<< File: untitled.dat >>
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/> -
RE: Polymorphism - retrieving type information from thedatabase
I would disagree with your statement that either the object or data model
must be wrong. The problem is more fundamental-trying to store objects in a
relational database. The object and relational paradigms can be made to
work together, but usually only by compromising tenets of one or the other
(or both). Now granted, there are many ways of making them work
together-and some are definitely better than others.
CJ
Chris Johnson
612-594-2535 (direct)
612-510-4077 (pager)
-----Original Message-----
From: Rottier, Pascal [SMTP:[email protected]]
Sent: Monday, June 15, 1998 8:17 AM
To: Forte Users Mailing list
Subject: RE: Polymorphism - retrieving type information from
the database
> ----------
> From: Rottier, Pascal[SMTP:[email protected]]
> Sent: Monday, June 15, 1998 8:17:16 AM
> To: Forte Users Mailing list
> Subject: RE: Polymorphism - retrieving type information from
the database
> Auto forwarded by a Rule
>
This issue has already passed this mailing list a couple of
times in the past. To put it in more general terms, you have
different classes which you store in the same DB table.
This is always tricky. Nine out of ten times, this means
either your Object model or your DataBase model is wrong.
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>This issue has already passed this mailing list a couple of
times in the past. To put it in more general terms, you have
different classes which you store in the same DB table.
This is always tricky. Nine out of ten times, this means
either your Object model or your DataBase model is wrong.
If you can differentiate between different classes, this
means you're dealing with different entities, which should
be stored in different tables. What if one class has an
attribute the other one doesn't. This would mean you have
to add a column to the database which is filled it the row
represends one class and is NULL if the row represends
another class. This is not good database practice!
Differentiating between different classes by means of
a "type" attribute is the classic procedural approach.
The OO approach would be to create subclasses. How-
ever, a relational database doesn't support subclasses.
The best way, would be to have a different table for
each subclass. If this gives you problems with norma-
lizing your database, you can create a table with all
the attributes generic to vehicle, and a table for each
subclass with only the attributes relevant to this sub-
class and a foreign key relation to the main table. If all
of this is not feasable, you're left with the need to find
some mechanism to identify what kind of class a cer-
tain row represends and then instantiate this class. The
tree solutions you suggested all work. It doesn't really
matter which one you chose, they're all equally dirty.
Hope this helps,
Pascal.
-----Original Message-----
From: General [SMTP:[email protected]]
Sent: Monday 15 June 1998 12:20
To: [email protected]
Subject: Polymorphism - retrieving type information from the
database
Suppose I have a class structure containing one base class with
several specialisations. Say, "Vehicle", with specialisations of
"Car", "Van" and "Truck". All vehicles are persisted in the database,
in a rolled-up table, and I want a generic retrieval mechanism, which
fetches a vehicle based on the license plate number. (It will probably
be a service object, which I will call a Persistent Object Manager).
I wish to retrieve ALL vehicles, and calculate the road tax for each.
However, cars, vans and trucks are all subject to different tax rules,
and require a different method to calculate their road tax. To put it
another way, there is a polymorphic method 'CalculateRoadTax' on the
"Vehicle" class.
Q: As each vehicle is extracted from the database, how does the rest
of the Forte application know what type of vehicle it is?
I am sure that others must have solved this problem before, but it is
new to us. We have come up with the following solutions:
(1) Add a "sub-type" column to the "Vehicle" table. Use the type
information to instantiate a Forte object of the correct type
(2) Maintain a completely separate table linking the vehicle licence
plate to its sub-type.
(3) Deduce the type of the object from the pattern of null columns in
the row.
I think (1) is the best solution, but I'm interested to know what the
experts say!
Incidentally, if Express can help or hinder in this situation, I would
be interested in that as well.
regards,
Tim Kimber
EDS (UK)
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
Maybe you are looking for
-
Problem in purchase order report
hi experts i am developing po report my output is po, line item, goods receipts, pending po. but in po no o/p like 2001, 20001 20001 20002 and 1 po contain line item but its corect my problem is i want po no like 20001 20002 20003, there is no repe
-
Acrobat error when opening pdf email attachments
I have a user who has the latest version of Adobe Acrobat and Reader installed on his PC running Windows 7 Pro SP1 which is up to date on patches. He was unable to open any pdf documents attached to email and was getting an error from Acrobat saying
-
HTTP 500 internal server error occured...
i want a HP-UX itanium version of Oracle 10gR2.. but.. url is broken.. why??
-
Warning For a Document that Deviates from the Budget:
Good Day! I want to have a warning for accounts that I used that deviates from a monthly budget. What I did is in the General Settings>>Budget Tab, I click budget Initialization and click WARNING", for monthly budget and also tick Purchase Orders,G
-
Keep getting the error message?
This is driving me crazy. I know my Apple ID and both my email and password are correct. I bought few games and one of the games are called Heli ****. I want to buy the points or DLC but I can't. I keep getting the message saying " The Apple ID you e