Polymorphism

Hai All
I hava doubt regrading polymorphism concept . Firstly please look in to this program then explain me clearly
class Shape
protected Color color;
protected int x, y;
Shape (Color c, int xPosition, int yPosition)
color = c;
x = xPosition;
y = yPosition;
} // constructor
public void drawShape (Graphics g)
g.setColor (color);
g.drawString ("Shape", x, y);
} // method drawShape
} // class Shape
class Circle extends Shape
private int radius;
Circle (Color c, int x, int y, int r)
super (c, x, y);
radius = r;
} // constructor
public void drawShape (Graphics g)
g.setColor (color);
g.fillOval (x, y, 2*radius, 2*radius);
} // method drawShape
} // class Circle
class Rectangle extends Shape
private int width, height;
Rectangle (Color c, int x, int y, int w, int h)
super (c, x, y);
width = w;
height = h;
} // constructor
public void drawShape (Graphics g)
g.setColor (color);
g.fillRect (x, y, width, height);
} // method drawShape
} // class Rectangle
if i want to access Circle drawShape method i can do like this :
Circle ob=new Circle();
ob.drawShape();
likewise i can access Rectangle drawShape method i can do like this :
Rectangle ob=new Rectangle ();
ob.drawShape();
instead of doing , some one trying to access some this way
Shape ob=new Rectangle();
Rectangle rectangle=(Rectangle)ob;
rectangle.drawShape();
Circle circle=(Circle)ob;
circle.drawShape();
please explain me what exact different between this two way . i hava been trying to find exact solution for this but i am not able .
Thanks
Selvakumar

I don't know what your question is. The following are the same.
Circle c = new Circle(...);
c.drawShape(g);
Shape shp = new Circle(...);
shp.drawShape(g);..because in both cases you are sending the same object the same message: draw yourself!

Similar Messages

  • 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,
    Markus

    Andrejus' 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.

  • Concept of Abstraction and Polymorphism

    Hi friends,
    I'm just new to Java.I studied a little bit of C, I'm currently studing VB and Java.
    There are one or two concepts in Java that are very hard to grasp for me.
    The first is abstraction and the second is polymorphism.
    Can anybody outline to me in simple words(use simple example if needed)what those 2 concepts are all about?
    Thanks a lot
    Marco

    In your example, you could make Vehicle an abstract
    class. You can't simply have a vehicle, but you can
    have a car which IS a vehicle. In your abstract class
    Vehicle, you might define an abstract method public
    int getSeats() (you want it to be abstract because it
    changes from one type of vehicle to the next). So the
    class Car extends Vehicle, overrides the method
    getSeats() and returns 5. The class Ute extends
    Vehicle, overrides the method getSeats() and returns 2
    (you might make a SuperCabUte that extends Ute and
    returns 5, or whatever).Radish is right,
    Think of it as modelling of real life. You would generalise the description of your car as a Vehicle (abstraction, which can be implemented as an interface in Java) where in fact you own a car
    Similarly you can have an inteface called RealEstate where in fact you own a TwoStoreyHouse ( a class that implements the RealEstate interface)
    the interface can describe the general 'characterstics' of real estate properties ie land size, council rates etc.
    HTH...hey....

  • What is the advantages of polymorphism over method overriding?

    what is the advantages of polymorphism over method overriding,that means if we are able to to create object at different instances at diff time for that sub class reff variable than what is the need of careating object of super class data type(i.e why always it is necessary to have upcasting for polymorphism?but if we can achive the same output without upcasting).....please tell me..lets have complete discuss..

    Seriously though....
    WebLogic (for which I have deployed many apps on) as
    well as Websphere are both high end Java application
    servers, meaning J2EE servers (in short). They allow
    one to deploy Enterprise Archive(EAR), a Web
    Archive(WAR), or an EJB Archive (in a JR file).
    These two servers allow one to deploy EJBs, use
    e JNDI, JMS, connectors, and other J2EE technologies
    - Tomcat does not. well, EJBs - no
    JNDI, yes - http://tomcat.apache.org/tomcat-4.1-doc/jndi-resources-howto.html
    JMS - yes (with an implementation, such as ActiveMQ: http://activemq.codehaus.org/Tomcat)
    Not sure what you mean by "connectors".
    Tomcat provides quite a bit of functionality (but yes, no EJBs)

  • How do I Open a Vi reference to and run a Polymorphic VI?

    In my case, I was trying to use a PolyVI Refnum to an instance of PID.vi. Even though I set the inputs for some of the controls, I have no output.the Invoke Method of 'Run VI' does not return an error. The Invoke Method of Ctrl Val. Get All does not return an error, but also returns an empty array on the character array.
    The problem seems to be with how VI server handles PolyVI Refnums, the constant for Polymorphic VIs. There does not seem to be an explicit way to determine which instance of the polymorphic VI should be used.
    Consequently, 'Ctrl Val.Get All' does not return any results from a 'Run VI' call. The array size is #0.
    Any ideas on what might be going on? Is there a better way to use a PolyVI Reference with VI server calls? I can't use Call By Reference Node since I can't seem to strictly type a Polymorphic VI (I can't select that check box on the Static VI Reference).

    Polymorphic VIs are an edit-time feature. They make no sense in run-time. Since you know at edit time which VI from the polymorphic group is actully going to be used, just open a reference directly to it. The polyVI itself only keeps a list of all the VIs that belong to it.
    Try to take over the world!

  • RE: Polymorphism - retrieving type information from thedatabase or how

    Don,
    Ok but if I was to model a real restaurant, I would then have a head chef
    that can then delegate to other chefs. This head chef would have the
    additional task of coordinating the completion of subservient chefs. This
    does not and would not mean that the head chef is stuck (or partitioned) in
    one part of the kitchen. Further a head chef would most likely also be a
    chef so that he would be running around the kitchen using and interacting
    with different objects to get his part of the recipe completed. Then once
    all chefs have completed their part of the recipe the head chef could return
    the meal.
    I would also point out that it does not make sense to me to be talking about
    the chef and its ability to scale. I would look that the resource limited
    devices that must be used to prepare meals to see scalability. In this case
    the grill, the stove and the microwave. Scalability of the restaurant is a
    function of the amount of resource limited devices versus the number of
    process (i.e. chefs) that need to use those devices concurrently and the
    amount of time they require access to those devices. By talking about chefs
    as if they are the scalability limiting factor seems to bring us back to the
    notion that the chef is a manager object that is shared. And again I come
    back to the question, why?
    You may now think that in a real restaurant, there are only so many chefs so
    why not make it a shared service? Well in a real restaurant there are only
    so many of any object, but this is not a consideration in our restaurant
    model. In our "virtual" restaurant hiring a chef is as easy as:
    Chef = new;
    And of course chefs are of zero mass so there can be a whole lot in the
    kitchen. Now assuming the Grill, Stove and Microwave map to physical
    objects in our computing environment, then that is the limiting factor and
    are therefore partitioned. Whenever communication has to go through a
    single source, then scalability breaks down. I fear that too many people
    make shared objects and create communication bottlenecks where they simply
    don't exist. The only place your scalability bottlenecks should exist is in
    the actual resource limited objects of your computing environment. Simply
    said, if something isn't a resource limited object, then why is it shared?
    If anyone is not clear how to architect an application independently of the
    business model, then I would suggest looking at various framework products
    and reading some technical architecture white papers to get a different, and
    possibly enlightening, point of view.
    Mark Perreira
    Sage IT Partners.
    -----Original Message-----
    From: Don Nelson [mailto:[email protected]]
    Sent: Wednesday, June 17, 1998 9:04 AM
    To: Mark Perreira
    Cc: [email protected]
    Subject: RE: Polymorphism - retrieving type information from the
    database
    Mark,
    First, I completely agree about the naming. I purposely used rather
    euphamistic names for these "managers", since I see many convoluted names
    for common things in various applications. But that is a topic for another
    thread...
    Simply because there is a "manager" of some type, does not imply that it is
    chained to a particular duty. However, let's look at a real life case. In
    a large restaurant, you would rarely see a chef chopping carrots or serving
    dishes to customers. Those are the responsibilities of the sous-chef and
    the waiter. So, we see that the chef does not really follow the food
    around. Why not? Because it simply doesn't scale. When scalability isn't
    a problem, (the restaurant isn't that popular, for example) the chef has
    some lattitude to accept more responsibility, and might even get involved
    with purchasing, etc.
    In the real world, the more scalable something has to be, the narrower the
    responsibilities are for each of the participating members.
    Don
    At 12:59 AM 6/17/98 -0700, Mark Perreira wrote:
    Don,
    One thing that always baffles me is when should an Object get the moniker
    "Manager." This practice seems to tell me a couple of things about these
    objects. In general when someone makes reference to a "Manager" objectthat
    it is probably a service object and probably contains no or very little
    attribution. The question is why? If I am developing an object model why
    am I thinking about such implementation issues.
    Surely if you are trying to model cooking an egg I would not see
    "SustenancePreparationManager" in your model. Using a more common term I
    would still be alarmed to see "CookManager" in your model. What does the
    CookManager manage? Does it manage other cooks or eggs. Maybe it shouldbe
    called an EggManager, but that doesn't make sense. How about just Cook.
    There that seems like the real world. And this brings me to a problem in
    the analogy. Conjuring up managers in a model can sometimes make you missa
    container. For example, I would say that if we wanted to model the real
    world, then eggs is a specialization of ingredient that is contained by
    recipe that can be given to a cook to be prepared.
    I may have many cooks (objects) that can prepare recipes and my application
    architecture not the object model needs to deal with how to best let those
    cooks utilize the grill, stove and microwave that sits on different
    partitions on my server. My cooks can move around and when they do they
    take their ability to know how to cook with them. In the real world Iwould
    expect a cook to use the right appliance to prepare the recipe based on its
    contents. I would not chain every cook to its appliance and them make me
    responsible for giving the right cook the right recipe. This is what
    managers can cause. They cause the consumer of cooks to know which cookcan
    prepare what recipes based on where they are chained. This then makes me
    know something about cooking. And if I don't know anything about cooking I
    can only image what my egg would look like if I accidentally gave therecipe
    to the cook stationed at the microwave.
    Ok Ok, I have seen many architectures use facades to hide the fact that I
    like to chain my cooks to their appliance. But what is that. I have gone
    to restaurants and I don't know what a cook facade is. If I ask themanager
    to present the cook facade manager employee I would probably be met by the
    bouncer employee.
    So what is the answer? Well for a start keep the application architecture
    out of the model. The model should stand alone in describing the
    interactions required to satisfy use cases. Second find an architecture
    that describes a more responsibility driven design and how that design and
    can map your business object behavior to a physical implementation with
    appliances and cooking rules. And lastly, don't be so quick to chain your
    cooks to their appliances. Give them some control over where they cook
    their recipes, after all that is what they do.
    Mark Perreira
    Sage IT Partners.
    -----Original Message-----
    From: [email protected]
    [<a href="mailto:[email protected]">mailto:[email protected]]On</a> Behalf Of Don Nelson
    Sent: Tuesday, June 16, 1998 2:07 PM
    To: Nick Willson
    Cc: [email protected]
    Subject: Re: Polymorphism - retrieving type information from the
    database
    This thread is switching context a bit, but I would add one thought tothe
    idea of encapsulating behavior. One of the advantages to OO is that it
    helps us model real world behavior. In the real world, I would not askan
    invoice to stuff itself into an envelope and mail itself to its
    customer; I
    would not ask my vehicle to fuel itself or change its own oil; I wouldnot
    tell an egg carton to ask one of its eggs to fry itself. Even if these
    things were physically feasible, I could list a number of reasons why I
    still wouldn't want to do them. That is why we haveVehicleRepairManagers
    and SustenancePreparationManagers (aka, "Mechanics" and "Cooks").
    Don
    At 11:28 PM 6/15/98 -0700, Nick Willson wrote:
    Tim,
    You've had lots of good suggestions so I hope you won't mind an attempt
    at another one. The consensus seems to be for your option (1) for the
    Vehicle table, and Steve's example of a GenericConstraint (taking the
    place of your Vehicle) is probably how most people would go about
    answering your question. I don't have much to add to that, just wanted
    to offer something about where the persistence mechanism lives and how
    things look to clients that depend on it.
    Suppose for a moment you think about the Vehicle classes' persistence as
    being just one aspect of their behavior. In addition to persistence,
    you might have to implement security, or locking for concurrent access,
    or caching of vehicle objects to improve performance, and of course you
    want to calculate the vehicle tax and probably do other things with
    Vehicles too.
    You can put the persistence aspect of Vehicles into a
    PersistenceObjectManager, but then the others need somewhere too. If
    you use a bunch of Managers (one for security, one for locking...) then
    each class's behavior is scattered across these various Manager classes,
    each of which has to know about many classes. Or if you use one Manager
    class, it's going to know still more, plus you are forced to implement
    all the behavior in (or at least via) that manager's partition.
    An alternative would be to keep all the Vehicle classes' behavior
    encapsulated together, so a client always makes requests to a Vehicle,
    and the Vehicle delegates the implementation of requests to a chain of
    handler objects that hang off the vehicle object (a handler for
    security, another for persistence, and so on).
    One of the nice things about this is, the handlers can be responsible
    for going to another partition (if necessary), e.g. to perform
    persistence operations, or for more business-specific operations like
    tax calculations. And because the handlers are smart, you don't have to
    put a lot of code into service objects, the SOs can stay pretty simple.
    This isn't an approach you'll see in Express, so I hope of it's of some
    interest.
    General wrote:
    Part 1.1 Type: Plain Text (text/plain)
    Encoding: quoted-printable--
    Nick Willson
    SCAFFOLDS Consultant,
    Sage IT Partners, Inc.
    (415) 392 7243 x 373
    [email protected]
    The Leaders in Internet Enabled Enterprise Computing
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>>
    >>>
    >>
    >>
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >
    >
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>

    Don,
    You are absolutely correct. But this is where I honestly think you are
    missing the point. While the mail program sends the mail, my mail message
    has an interface (i.e. send button) which can delegate that to the mail
    program. This makes it nice and simple for me the consumer of the mail
    program. It also means I can think of mailing by focusing on the interface
    (i.e. the button). It would suck if every time I wanted to mail something I
    had to identify the correct pop server to send it to (i.e the MailManager).
    Mailing something is the collaboration of the setup information of the mail
    program and my mail message. If I were to model this my mail object would
    indeed have a send method that could delegate to the correct mail servers.
    This is just simplicity of interface and it is a good practice in UI
    development just as it is in business model development. A simpler
    interface, I think we can all agree, provides for a better and quicker
    understanding.
    Mark Perreira
    Sage IT Partners.
    -----Original Message-----
    From: [email protected]
    [<a href="mailto:[email protected]">mailto:[email protected]]On</a> Behalf Of Don Nelson
    Sent: Thursday, June 18, 1998 9:22 AM
    To: Nick Willson
    Cc: [email protected]
    Subject: Re: Polymorphism - retrieving type information from the
    database
    Nick,
    It turns out that your message does not, indeed send itself. Your mailing
    program does that.
    Don
    At 11:54 PM 6/17/98 -0700, Nick Willson wrote:
    Hey Don,
    In the real world, no, you can't tell an invoice to put itself into anenvelope
    and mail itself. You have to know about stamps and post boxes and wherethey
    are located. But isn't it nice that in software you don't have to followthe
    real world very closely if you don't want to?
    Above the top left hand corner of this message I'm typing right now, thereis a
    send button which lets me tell the message to 'stuff itself into anenvelope
    and mail itself'. Why wouldn't you want to do that?
    Don Nelson wrote:
    This thread is switching context a bit, but I would add one thought to
    the
    idea of encapsulating behavior. One of the advantages to OO is that it
    helps us model real world behavior. In the real world, I would not askan
    invoice to stuff itself into an envelope and mail itself to its customer;I
    would not ask my vehicle to fuel itself or change its own oil; I wouldnot
    tell an egg carton to ask one of its eggs to fry itself. Even if these
    things were physically feasible, I could list a number of reasons why I
    still wouldn't want to do them. That is why we haveVehicleRepairManagers
    and SustenancePreparationManagers (aka, "Mechanics" and "Cooks").
    Don
    At 11:28 PM 6/15/98 -0700, Nick Willson wrote:
    Tim,
    You've had lots of good suggestions so I hope you won't mind an attempt
    at another one. The consensus seems to be for your option (1) for the
    Vehicle table, and Steve's example of a GenericConstraint (taking the
    place of your Vehicle) is probably how most people would go about
    answering your question. I don't have much to add to that, just wanted
    to offer something about where the persistence mechanism lives and how
    things look to clients that depend on it.
    Suppose for a moment you think about the Vehicle classes' persistence as
    being just one aspect of their behavior. In addition to persistence,
    you might have to implement security, or locking for concurrent access,
    or caching of vehicle objects to improve performance, and of course you
    want to calculate the vehicle tax and probably do other things with
    Vehicles too.
    You can put the persistence aspect of Vehicles into a
    PersistenceObjectManager, but then the others need somewhere too. If
    you use a bunch of Managers (one for security, one for locking...) then
    each class's behavior is scattered across these various Manager classes,
    each of which has to know about many classes. Or if you use one Manager
    class, it's going to know still more, plus you are forced to implement
    all the behavior in (or at least via) that manager's partition.
    An alternative would be to keep all the Vehicle classes' behavior
    encapsulated together, so a client always makes requests to a Vehicle,
    and the Vehicle delegates the implementation of requests to a chain of
    handler objects that hang off the vehicle object (a handler for
    security, another for persistence, and so on).
    One of the nice things about this is, the handlers can be responsible
    for going to another partition (if necessary), e.g. to perform
    persistence operations, or for more business-specific operations like
    tax calculations. And because the handlers are smart, you don't have to
    put a lot of code into service objects, the SOs can stay pretty simple.
    This isn't an approach you'll see in Express, so I hope of it's of some
    interest.
    General wrote:
    Part 1.1 Type: Plain Text (text/plain)
    Encoding: quoted-printable--
    Nick Willson
    SCAFFOLDS Consultant,
    Sage IT Partners, Inc.
    (415) 392 7243 x 373
    [email protected]
    The Leaders in Internet Enabled Enterprise Computing
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>>
    >>>
    >>
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes--
    Nick
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href="http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >
    >
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>

  • JAXB Polymorphism of little use

    HI all.
    I am finding little use in JAXB's polymorphism. As such, I think I'm going to need to switch to another framework that has a more useful polymorphism feature (or else none at all).
    As indicated below, I have a schema that includes a "Person" complex type, and an "Employee" complex type that extends it. There is also an element "people" that is a sequence of "Person" elements. I have used JAXB-generated classes to add instances of Person and Employee (generated classes) to an instance of the People class. The marshaller then erroneously outputs the extensions to Person found in Employee (see below).
    Having seen this, I wonder what use polymorphism (in the classes generated by JAXB) has, if it is not acceptable to use a subclass wherever its superclass is allowed. Perhaps there is some other way to do polymorphism that I'm missing?
    I really want to have a functionality such as the code example below implies. Does JAXB have the feature I'm looking for, or do I need to switch to another framework? If I need to switch, which one should I use?
    Thanks for any help that can be offered.
    schema:
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:element name="people">
              <xs:annotation>
                   <xs:documentation>Comment describing your root element</xs:documentation>
              </xs:annotation>
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="person" type="Person" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:complexType name="Person">
              <xs:sequence>
                   <xs:element name="name" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="Employee">
              <xs:complexContent>
                   <xs:extension base="Person">
                        <xs:sequence>
                             <xs:element name="title" type="xs:string"/>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
    </xs:schema>
    expected JAXB output:
    <people>
    <person>
    <name>Joe Sample</name>
    </person>
    <person>
    <name>Jane Sample Employee</name>
    </person>
    </people>
    actual JAXB output (invalid):
    <people>
    <person>
    <name>Joe Sample</name>
    </person>
    <person>
    <name>Jane Sample Employee</name>
    <title>Engineer</title>
    </person>
    </people>
    Java code:
    Person person = factory.createPerson();
    person.setName("Joe Sample");
    Employee employee = factory.createEmployee();
    employee.setName("Jane Sample Employee");
    employee.setTitle("Engineer");
    People people = factory.createPeople();
    people.getPerson().add(person);
    people.getPerson().add(employee);
    - Matt Munz

    hi Matt,
    I think your expected output may be wrong, and the actual output be correct eg consider this code:
    import java.util.*;
    class Person {
         String name;
         public String toString() { return "Person("+name+")"; } }
    class Employee extends Person {
         String title;
         public String toString() { return "Employee("+name+", "+title+")"; } }
    public class JBTest {
         public static void main(String[]arg) {
              List l = new ArrayList();
              Person p = new Person();
              p.name="Joe Sample";
              Employee q = new Employee();
              q.name="Jane Sample Employee";
              q.title="Engineer";
              l.add(p);
              l.add(q);
              System.out.println(l);
    which outputs
         [Person(Joe Sample), Employee(Jane Sample Employee, Engineer)]
    So although the List is untyped (am not keeping up with generics..
    sorry!) in the above code, even if it were a Person list it would still be legitimate to add an Employee to the list (since an Employee is-a
    Person)
    saying that, am not sure how you could achieve what you are trying? are you hoping for the object tree you construct not to be validated?
    thanks,
    asjf

  • Using a polymorphic view object with binding

    Hi,
    I'm hoping there's something simple I'm missing when trying to setup up the bindings for a ADF/struts page using a polymorphic view object.
    I'm using Entity and VO polymorphism to create a Question which has different types - boolean, multi-choice, likert, etc. I have the various question types created as sub type entity and view objects and added to the app module - when added to the app module the question types are subtypes of QuestionView so they don't actually appear in the Data Controls palette. This setup is like that used in Steve Muench's examples (blog at http://radio.weblogs.com/0118231/stories/2003/02/06/constructingTheDesiredEntityInAPolymorphicViewObject.html and the related undocumented one)
    My question is, how do I get to the data and have jdev create the necessary bindings for the extra attributes the subtype questions have? Since they don't appear as available data controls I can't create a binding iterator or anything for them - short of adding them as spearate view objects (which destroys the whole point of using polymorphism in this case) is there a way to do this?
    Really, the only reason I want to use the polymorphism is so I can have different types of entity validation depending on the type. Should I just simplify this to be one entity object with one VO and put all the validation into "if else's" based on a discriminator?
    Assistance appreciated...
    - Nathaniel

    How else are you planning to associate a JUTableBinding to the 'common' iterator containing all four types of rows and then selectively display them? Perhaps you'd need a custom model over the JUTabelModel that'd filter the rows out.
    I'm not sure if all that trouble is worth it given that your datasets (as far as mentioned in this post) are not large. If these tables/data has to be refreshed/executed a number of times, then you may see the overhead of four queries otherwise it should be fine as database is always faster in filtering rows than doing that in memory.

  • Abstract Class and polymorphism - class diagram

    Hi,
    ]Im trying to draw a class diagram for my overall system but im not too sure how to deal with classes derived from abstract classes. I'll explain my problem using the classic shape inheritance senario...
    myClass has a member of type Shape, but when the program is running shape gets instantiated to a circle, square or triangle for example -
    Shape s = new circle();
    since they are shapes. But at no stage is the class Shape instantiated.
    I then call things like s.Area();
    On my class diagram should there be any lines going from myClass directly to circle or triangle, or should a line just be joining myClass to Shape class?
    BTW - is s.Area() polymorphism?
    Thanks,
    Conor.

    Sorry, my drawing did not display very well.
    If you have MyClass, and it has a class variable of type Shape, and the class is responsible for creating MyClass, use Composition on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it has a class variable of type Shape, and the class is created elsewhere, use Aggregation on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it is used in method signatures, but it is not a class variable, use Depedency on your UML diagram to link Shape and MyClass. The arrow will point to Shape.
    Shape and instances of Circle, Triangle, Square, etc. will be linked using a Generalization on your UML diagram. The arrow will always point to Shape.
    Anything that is abstract (class, method, variable, etc.) should be italicized. Concrete items (same list) should be formatted normally.
    BTW, the distinction between Composition, Aggregation and Dependency will vary from project to project or class to class. It's a gray area. Just be consistent or follow whatever guidelines have been established.
    - Saish

  • What's a polymorphic terminal and why can't I change the colour of an LED?

    Hi,
    I've written a small vi to experiment with changing the
    colour of an LED from the front panel by the user. (See attached.)
    I've created a property node for the LED indicator and selected the 'Colors[4]' property.
    I've then selected the 0th element of the array using 'Index Array' and used this as the cluster type on 'Bundle By Name' but no names appear in the elements.
    When I then try to wire a colour box to the input of Bundle By Name I get a broken wire and the message: "This wire connects to a polymorphic terminal that cannot accept this data type".
    And yet when I hold the mouse over the wire from the output of index array so it's just looking at one element of the colors[4] array in the help window I'm told it's a cluster made up of two U32's. Individually these are the same data type as the output from the colour box.
    What's a polymorphic data type and what's the correct way to wire from the colour selection box to the Colors[4] property of the LED so the colour can be changed?
    Any help much appreciated.
    Thanks,
    Dave.
    Attachments:
    LED_colour.vi ‏25 KB

    Dave,
    A couple of comments.
    As CC said, you need to use the plain bundle node.
    If you want to change the "ON" color, you need element 1, not zero.
    Property operations should only be done exacly once whenever something changes, not 10000 times/second. Use an event structure.
    See attached (LabVIEW 7.0). Modify as needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    LED_colourMOD.vi ‏34 KB

  • Polymorphic VI editor bug

    When you add a VI to a polymorphic VI, the highlighted VI in the "Instance VIs" is not the one you just added (unless the polymorphic VI has only one instance VI).  To recreate issue: create a polymorphic VI, add two instance VIs to it, now add a third - when you add it and return to the plymorphic VI editor the 0th VI is selected (expected behaviour: the newly added VI is selected).  This adds an unessisary step when editing the name of the instance VIs (especially when you have a polymorphic VI with over 20 instance members).
    Copyright © 2004-2015 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 2.5 License.

    I agree this behavior is kind of strange.  This was reported to R&D (102930) for further investigation.

  • Runtime Polymorphism

    Hi
    Asper the code snippet below:
    What is the advantage that we get by declaring the object as in Statement 1 over the declaration in Statement 2 below, when both obj1 and obj2 can perform all methods available in subclass B. Moreover as per what I know, obj1 can not access those methods of class B which are not available in class A whereas obj2 can perform all methods of class A as well as class B ???
    Then why do programmers use Statement type of declaration???
    Runtime polymorphism also occurs if I declare it in the Statement 2 way, the show() function as described in both classes gets overridden.
    Can anyone read the problem statement carefully and really explain me why anyone would ever want to use Statement 1 declaration when there there is no harm in Statement 2 declaration and rather an advantage that obj2 can use all the class B's functions whereas obj1 might not be able to do so? Is there anything that I am missing here?????
    Am a novice programmer, forgive me if I am missing something. Kindly clarify my doubt if you have time.
    Class A{
       void show(){
          System.out.println("Am in A");
    Class B extends A {
       void show(){
          System.out.println("Am in B.");
    Class Test{
       public static void main(String[] args){
          A obj1 = new B();  // Statement 1
          B obj2 = new B();  // Statement 2
          obj1.show();
          obj2.show();
    }

    justgig8 wrote:
    Runtime polymorphism also occurs if I declare it in the Statement 2 way, the show() function as described in both classes gets overridden.
    Can anyone read the problem statement carefully and really explain me why anyone would ever want to use Statement 1 declaration when there there is no harm in Statement 2 declaration and rather an advantage that obj2 can use all the class B's functions whereas obj1 might not be able to do so? Is there anything that I am missing here?????In your limited example, there's really no non-trivial advantage. We had a long, drawn out argument about this recently, but basically it boils down to, "in general, if possible, code to the interface (or least concrete type)". In your example, it might be that main() becomes a long, complex method, and one day somebody tells you that it would work 20 times faster if you used a (C extends A) instead of a B. If you were using the first declaration, it'd be an easy switch. If you were using the second, it might not be.
    But the real power of coding to the interface (and polymorphism in general) is for less trivial situations, where the choice of type is not fully encapsulated as it is in your example.

  • 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 Vervecken

    fyi
    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

  • Polymorphic question

    this is one of the questions for the java exam . i don't seem to understand the answer.
    class SuperBase
        void print (SuperBase a)
            System.out.print("Super");
    class Base extends SuperBase
        void print (Base b)
            System.out.print("Base");
    class Derived extends Base
        static void print (Derived c)
            System.out.print("Derived");
    public class Test {
        /** Creates a new instance of Test */
        public static void main (String args[])
            SuperBase a1 = new SuperBase();
            SuperBase b1 = new Base();
            Base c1 = new Derived();
            a1.print(new Base());
            b1.print(new Derived());
            c1.print(new Derived());
    }the answer to this is super super base. i compiled and checked it.
    I thought the answer would be super base base.
    since b1 is a object type base with a reference variable of type superbase when the method is called at runtime i thought it would make a Polymorphic call the base method. therefore printing base for this call b1.print(new Derived());
    I hope someone can explain why this is not the case. Thank you for your help.

    sorry sujji i still don't get it.
    i thought for example if you got a horse class which extends an animal class which both contain for example an eat method ie public void eat()
    then
    Animal a = new Animal();
    Horse b = new Horse();
    a.eat(); //runs animal version
    b.eat(); // runs horse version
    does this mean the base method is not overidding the SuperBase class print method but actually overloading it.
    void print (SuperBase a) // in SuperBase class
    void print (Base b)// in Base Class
    if thats the case i understand, otherwise i am now completely lost.

  • Select instance of polymorphi​c vi at compile time

    quick question:
    I have a fairly significant labview project that i'm deploying to several compactRIOs.  However, I have two possible configurations of that code.  The difference between the two configurations is a single VI.  That is, within my project, there's one VI that I replace with another (same connector pane) for the alternate configuration.
    What I want to do is to make that VI into a polymorphic VI, then have the instance of that polymorphic VI be set at compile time.  That is, I would have two build specifications.  Each build specification would build a configuration of the project by having the selection of which instance of the polymorphic VI to use be included as a parameter of the build specification.  If it is possible to do, I can't seem to find the option in the build specification preferences to do so.
    Does this make sense?  Any help is appreciated.
    Cheers.
    Solved!
    Go to Solution.

    Keith_W wrote:
    yamaeda, i'm unclear about what you're suggesting.  are you suggesting that i use the VI scripting VIs to programmatically edit the VI to switch which state is enabled by using a VI that runs before building, but as part of the build process?
    The Conditional disable seems to work like a script at compile time. As you stated your problem it sounds like you wanted 2 builds anyway, and this would enable one of the conditional frames when building the exe.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Plsql object type polymorphism

    Hi everyone.
    Is adhoc polymorphism possible in pl/sql using Oracle's object types? Here is some sample code that I tried on an Oracle 10.2.0.3 64-bit database running on Solaris.
    Connected.
    09:58:58 SQL> create type root_ty as object (
    09:59:03   2    a1     varchar2(32 char)
    09:59:03   3  ) not final
    09:59:03   4  /
    Type created.
    Elapsed: 00:00:00.17
    09:59:05 SQL> create type sub_ty under root_ty (
    09:59:10   2    a2     varchar2(32 char)
    09:59:10   3  , constructor function sub_ty(str in varchar2) return self as resul
    09:59:10   4  , member procedure display_a2
    09:59:10   5  ) final
    09:59:10   6  /
    Type created.
    Elapsed: 00:00:00.06
    09:59:12 SQL> create or replace type body sub_ty is
    09:59:18   2    constructor function sub_ty(str in varchar2)
    09:59:18   3      return self as result
    09:59:18   4    is
    09:59:18   5    begin
    09:59:18   6      self.a2 := str;
    09:59:18   7     
    09:59:18   8      return;
    09:59:18   9    end;
    09:59:18  10   
    09:59:18  11    member procedure display_a2
    09:59:18  12    is
    09:59:18  13    begin
    09:59:18  14      dbms_output.put_line('a2 value is .... '||a2);
    09:59:18  15    end;
    09:59:18  16  end;
    09:59:18  17  /
    Type body created.
    Elapsed: 00:00:00.04
    09:59:20 SQL> set serveroutput on
    10:00:31 SQL> declare
    10:00:35   2    l_ty    root_ty;
    10:00:35   3  begin
    10:00:35   4    l_ty := new sub_ty('Woot!');
    10:00:35   5   
    10:00:35   6    l_ty.display_a2();
    10:00:35   7  end;
    10:00:35   8  /
      l_ty.display_a2();
    ERROR at line 6:
    ORA-06550: line 6, column 8:
    PLS-00302: component 'DISPLAY_A2' must be declared
    ORA-06550: line 6, column 3:
    PL/SQL: Statement ignored
    Elapsed: 00:00:00.06
    10:00:37 SQL> declare
    10:00:53   2    l_ty    root_ty;
    10:00:53   3  begin
    10:00:53   4    l_ty := new sub_ty('Woot!');
    10:00:53   5   
    10:00:53   6  --  l_ty.display_a2();
    10:00:53   7  end;
    10:00:53   8  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01
    10:00:53 SQL> declare
    10:01:30   2    l_ty    sub_ty;
    10:01:30   3  begin
    10:01:30   4    l_ty := new sub_ty('Woot!');
    10:01:30   5   
    10:01:30   6    l_ty.display_a2();
    10:01:30   7  end;
    10:01:30   8  /
    a2 value is .... Woot!
    PL/SQL procedure successfully completed.Certainly seems like this should be possible ... Am I missing something simple?
    Thanks for any input.
    - KR

    Here is an example of what polymorphism is supposed to do:
    SQL> create type bird as object
      2  (name varchar2 (30)
      3  , member function fly return varchar2
      4  , member function make_a_noise return varchar2)
      5  not final
      6  /
    Type created.
    SQL>
    SQL> create type birds_nt as table of bird;
      2  /
    Type created.
    SQL>
    SQL>
    SQL> create or replace type body bird as
      2
      3      member function fly return varchar2
      4      is
      5      begin
      6          return 'my name is '||self.name;
      7      end;
      8
      9      member function make_a_noise return varchar2
    10      is
    11      begin
    12          return 'generic twitter';
    13      end;
    14
    15  end;
    16  /
    Type body created.
    SQL>
    SQL>
    SQL> create type duck under bird (
      2  overriding member function make_a_noise return varchar2
      3  , member procedure waddle
      4  );
      5  /
    Type created.
    SQL>
    SQL> create or replace type body duck as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'quack!';
      8      end;
      9
    10      member procedure waddle
    11      is
    12      begin
    13          null;
    14      end;
    15
    16
    17  end;
    18  /
    Type body created.
    SQL>
    SQL>
    SQL>
    SQL> create type chicken under bird (
      2  overriding member function make_a_noise return varchar2
      3  , member procedure peck
      4  )
      5  not final;
      6  /
    Type created.
    SQL>
    SQL> create or replace type body chicken as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'cluck!';
      8      end;
      9
    10      member procedure peck
    11      is
    12      begin
    13          null;
    14      end;
    15
    16
    17  end;
    18  /
    Type body created.
    SQL>
    SQL> create type canary under bird (
      2  overriding member function make_a_noise return varchar2
      3  );
      4  /
    Type created.
    SQL>
    SQL> create or replace type body canary as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'I taught I taw a puddy tat!!!';
      8      end;
      9
    10
    11  end;
    12  /
    Type body created.
    SQL>
    SQL> create type rooster  under chicken (
      2  overriding member function make_a_noise return varchar2
      3  )
      4  ;
      5  /
    Type created.
    SQL>
    SQL> create or replace type body rooster as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'That''s a joke... I say, that''s a joke, son.';
      8      end;
      9
    10
    11  end;
    12  /
    Type body created.
    SQL>
    SQL>
    SQL>
    SQL>
    SQL> declare
      2      my_aviary birds_nt := birds_nt();
      3  begin
      4      my_aviary.extend(5);
      5      my_aviary(1) := duck('Donald');
      6      my_aviary(2) := chicken('Chicken Little');
      7      my_aviary(3) := canary('Tweetie Pie');
      8      my_aviary(4) := rooster('Foghorn Leghorn');
      9      my_aviary(5) := bird('?');
    10      for idx in my_aviary.first()..my_aviary.last()
    11      loop
    12          dbms_output.put_line( my_aviary(idx).fly() );
    13          dbms_output.put_line( my_aviary(idx).make_a_noise() );
    14      end loop;
    15  end;
    16  /
    my name is Donald
    quack!
    my name is Chicken Little
    cluck!
    my name is Tweetie Pie
    I taught I taw a puddy tat!!!
    my name is Foghorn Leghorn
    That's a joke... I say, that's a joke, son.
    my name is ?
    generic twitter
    PL/SQL procedure successfully completed.
    SQL>Now, in that loop woudl it make sense to execute a peck() on all of those entries? Nope. Furthermore as far as I can tell it is not possible to find out what sub-type an object is from with PL/SQL, so you couldn't even use Padders's TREAT ploy.
    So: if you want to do something generic use a super-type. If you want to do something specific use a sub-type.
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

Maybe you are looking for

  • Is there a way to delete an ebook from my iPad a and just leave it in the icloud

    I have books in my iPad from Kindle.Is there a way to delete the read books from my device and just leave them in the iCloud ?

  • VMware Fusion 4

    I've got a question. Is it possible to install vmware fusion 4 on 2 or more different macs? I need to install it on my macbook pro and my mac mini. greetings tigner

  • Host name change

    Hi, We are in the process of migrating our production system and we may have to change the host name. Is there any way we can convert all the host name entries to the new host name like we do for logical system change using 'BDLS'. Regards, Krishna.

  • MV45AFZB, MV45AFZZ  (VA01) Sales Document No

    Hi All, I have created screen exit for sales order creation tcode, and storing some data in ztable, everything is fine till here, only problem is i am not getting sales document number at the time of save event which should be captured at run time wh

  • Can't find iBooks pre-order/purchases section?

    I thought I had pre-ordered a book through iBooks, but when I access my account to verify the pre-order, I don't see anything that will allow my to view my pre-orders.  It said to click on purchases, but I don't see anything titled purchases.  The on