Inheritance/Abstraction question

Ok here is what I currently have. I have a base class, ORDERFROM, which I have made abstract. Then I have an interface, ORDERFORM_ACTIONS, whcih defines actions for an order form. Then I have a class ORDERFORM1. Is there a way to add some more abstraction to my order form family tree so I can have default methods with no parmeters? I am looking for a way to keep from having to implement all non parameter methods again for every new order form. I know they have to be implented in the base class for this to happen but what if the location changes? Keep in mind the location of the data items on the order from will change from revision to revision. Here is what the code structure looks like
public interface OrderFormActions{
   public boolean placeOrder();
   public String getName();
   public String getPhone();
public abstract class OrderForm implements  OrderFormActions{
  public OrderForm(){
  public String getName(int row, int col){
      String name = getCell(row, col);
  public String getPhone(int row, int col){
      String phone = getCell(row,col);
  public boolean placeOrder(){
public class OrderForm1 extends OrderForm{
  public OrderFrom1(){
     super();
  public String getName(){
    int row = 1;
    int col =  2;
    return super.getName(row,col);    // I know super is not needed used for illistration
  public String getPhone(){
    int row = 4;
    int col = 12;
    return super.getPhone(row, col);  // I know super is not needed used for illistration
}Ideas? As abstract as you can go?

I mean the interface methods have to implented in
some class. And if I don't want have to implement
all the interface methods in every inherited class
then I have will have to implement them in thebase
class. (Low cuppeling, high conhesiveness)Then, either you should not have an inerface with
th all those methods, or you should have an adapterThats totally wrong. Parent classes behavior is not governed by the sub classes. refer to Dependency Inversion Principle
http://www.eventhelix.com/RealtimeMantra/Object_Oriented/dependency_inversion_principle.htm
class that provides default behaviour from where
your classes can inherit or you should put those
default behaviour up in the class hierachy.Now thats an even worse advice. Under what conditions would you provide an adapter. This particular scenario is not one of them. refer to Software open closed principle.
>
May the code be with you.If you do things like this I guess the code would not be with you.

Similar Messages

  • Inherited abstract method IGCIControllerDelegate

    Hi,
    I created only view in NWDS,the implementation it can't recognize the IPrivateview and context values.i deleted and created agine but agine it shows same,and the error is inherited abstract method IGCIControllerDelegate,please give me solution,what is the problem?

    Hi Sumit,
    I closed and agine opened but iam getting the same error.Please tell me .

  • The type must implement the inherited abstract method???

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.ActiveEvent;
    import java.applet.*;
    public class MoveIt extends Applet implements ActionListener
         private Image cup;
         private Panel keyPad;
         public int yaxis = 15;
         public int xaxis = 15;
         private Button keysArray[];
         public void init()
              cup = getImage(getDocumentBase(), "cup.gif");
              Canvas myCanvas = new Canvas();
              setBackground(Color.blue);
              setLayout(new BorderLayout());
              Button up = new Button("Up");
              Button down = new Button("Down");
              Button right = new Button("Right");
              Button left = new Button("Left");
              Button center = new Button("Center");
              add(myCanvas, BorderLayout.NORTH);
              add(keyPad, BorderLayout.SOUTH);
              keyPad.add(up, BorderLayout.NORTH);
              up.addActionListener(this);
              keyPad.add(down, BorderLayout.SOUTH);
              down.addActionListener(this);
              keyPad.add(right, BorderLayout.EAST);
              right.addActionListener(this);
              keyPad.add(left, BorderLayout.WEST);
              left.addActionListener(this);
              keyPad.add(center, BorderLayout.CENTER);
              center.addActionListener(this);
         public void paint( Graphics g )
              g.drawImage( cup, xaxis, yaxis, this );
         public void ActionPerformed(ActionEvent e)
              String action = e.getActionCommand();
              if(action.equals("Up"))
                   yaxis = yaxis - 15;
              if(action.equals("Down"))
                   yaxis = yaxis + 15;
              if(action.equals("Left"))
                   xaxis = xaxis - 15;
              if(action.equals("Right"))
                   xaxis = xaxis + 15;
              if(action.equals("Center"))
                   xaxis = 125;
                   yaxis = 60;
    }How come there is an error:
    The type MoveIt must implement the inherited abstract method
    ActionListener.actionPerformed(ActionEvent)
    What the hell does that mean?

    A class that implements an interface must define the methods of the interface. Your applet (or the one you borrowed) states at the top that it implements the ActionListener interface. If you go to the API, you'll see that this interface declares a method "actionPerformed", and so this class must have a method that matches the one in the interface. I see that your applet will have some Buttons. You'll need an actionPerformed method if you want the buttons to use your class (this) as their action listener.
    Edit: I see that you already have an "ActionPerformed" method, but note that case matters, and this is not the same as "actionPerformed". Change one letter and you're on your way.
    Edited by: Encephalopathic on Jan 15, 2008 8:44 PM

  • Inheritance architecture question

    Hello,
    I've an architecture question.
    We have different types of users in our system, normal users, company "users", and some others.
    In theory they all extend the normal user. But I've read alot about performance issues using join based inheritance mapping.
    How would you suggest to design this?
    Expected are around 15k normal users, a few hundred company users, and even a few hundred of each other user type.
    Inheritance mapping? Which type?
    No inheritance and append all attributes to one class (and leave these not used by the user-type null)?
    Other ways?
    thanks
    Dirk

    sorry dude, but there is only one way you are going to answer your question: research it. And that means try it out. Create a simple prototype setup where you have your inheritance structure and generate 15k of user data in it - then see what the performance is like with some simple test cases. Your prototype could be promoted to be the basis of the end product if the results or satisfying. If you know what you are doing this should only be a couple of hours of work - very much worth your time because it is going to potentially save you many refactoring hours later on.
    You may also want to experiment with different persistence providers by the way (Hibernate, Toplink, Eclipselink, etc.) - each have their own way to implement the same spec, it may well be that one is more optimal than the other for your specific problem domain.
    Remember: you are looking for a solution where the performance is acceptable - don't waste your time trying to find the solution that has the BEST performance.

  • Inheritance related question

    class a{
         public void meth()
              System.out.println("In a");
    class b extends a{
         public void meth()
              System.out.println("In b");
    public class Test extends b{
         public static void main(String[]a)
    }can i call the a's meth() from Test without creating an instance of a? This might be a simple question and i think i cant create it, but if this is possible please tell me how to do it. also im not referring to runtime polymorphism. without using runtime polymorphism, can i access a's meth()? i know by calling super.meth() in b's meth() will solve it but i do not want to go that way.
    Thanks in advance,
    Geet

    meth is not a static method of the class a, so you can't really call it without instantiating class a.
    If you meant "can I call method meth in class a with an instance of class b?",(note that an instance of b is an instance of a) the answer is no as well, because your method from class b has overridden it... Note that you CAN call the method from class a from within class b (but not from Test), by using the keyword super.

  • Inheritance & Sorting Question

    Hi guys,
    I have created an abstract class Element and then three subclasses; Person, Sportsman and Date. The Person class has the fields such as name, surname, DOB ... The Sportsman class is extended Person class with some more fields and Date naturally has days, months and years. My task is to write a class Sort, which contains a few sorting methods (i.e. quicksort) and is able to sort any Element object.
    My original idea was to create an abstract method sort. For that method to work, I have to consider three parameters; an instance field the sort will be performed on, a type of sorting algorithm to use and an order of sorting (ascending/descending). The problem I stumbled upon is how to tell the method which instance variable to use; it could be done with a switch statement, but it seems so rough and, well, ugly.
    So I'm just wondering if there is a simpler way to do this. Also, if you have a better idea on how to get started with this, please let me know. (I'm not asking for the code, just for the opinion).
    Thanks,
    Ted

    Thank you both for a quick response.
    However, I forgot to mention that the sorting should be done without any help of Java library. Also, the main problem I have seems to be on how to "tell" a method which instance field I have chosen.
    Example:
    Suppose sort(Element e) is an abstract method. I want to sort all the given surnames in the class Person using quicksort in descending order. The method I had in mind should be something like this:
    sort(Element, String, int, int)and the call for the metod with the given arguments would be:
    sort(e, surname, 1, -1) {
       Person p;
       if (e instanceof Person) {
          p = (Person)e;
       // rest of the code
    }But since the argument surname was a String, how to tell a method sort that the field surname was actually chosen?
    If my plan does not makes sense, do tell.
    Thanks.

  • Inheritance/Overloading Question

    Hi,
    Can someone please explain why the following piece of code would fail to compile:
    class A
      void m1(int a)    { System.out.println("A"); }
    class B extends A
      void m1(double b) { System.out.println("B"); }
    class C extends B
      void m1(float c)  { System.out.println("C"); }
    class D
      public static void main (String[] args) {
        int i=10;
        C c = new C();
        c.m1(i);
    D.java:28: reference to m1 is ambiguous, both method m1(int) in A and method m1(float) in C match
    c.m1(i);
    From my understanding, B overloads the method m1 of A, and C did likewise. And when C extends B, it inherits the version of m1 in A and B. So C should have 3 versions of m1 available to it, just like this code:
    class C
      void m1(int a)    { System.out.println("A"); }
      void m1(double b) { System.out.println("B"); }
      void m1(float c)  { System.out.println("C"); }
    }Why then the compiler could not decide which method to invoke ? Another strange thing is that if the version of m1 of A and C where to be interchanged, the compiler will not complain.
    Thanks.

    The behaviour of the compiler is correct according to the JLS (par 15.12.2.2). The problem is that there is no most specific method. You need to know that the type of the class in which the method declaration occurs plays a role just as much as the type of the parameters when choosing the most specific method.
    Let us look at the specific case. I will discard the method in class B because it does not affect the result. Thus, we have two choices:
    1) A.m1(int) is not more specific than C.m1(float) because A cannot be converted to C by method invocation conversion.
    2) C.m1(float) is not more specific than A.m1(int) because float cannot be converted to int by method invocation conversion.
    (Look in par 5.3 for the precise definition of method invocation conversion. However, it is pretty straight forward what it means.)
    Thus, neither A.m1(int) nor C.m1(float) is more specific and therefore any call to C.m1 will be ambigious.

  • Inheritance usage question

    I have 2 classes, DBContainerGraphic and DBGraphic. The DBGraphic class has a static method called Create() which creates and returns a DBGraphic object. The DBContainerGraphic extends DBGraphic. DBContainerGraphic also uses a static factory method.
    Now, DBContainerGraphic is inheriting the static method from DBGraphic that instantiates and returns a DBGraphic. [note: it does have a different signature] This create method does not make sense in the context of DBContainerGraphic.
    It will work, but it is not returning a DBContainerGraphic, and thus I feel it should not be exposed on the DBContainerGraphic class.
    What should I do about this? Just ignore it? After all, it is only package scope.

    class DBGraphic
      static DBGraphic makeGraphic() { return new DBGraphic(); }
    class DBContainerGraphic
    extends DBGraphic
      static DBContainerGraphic makeContainerGraphic() { return new DBContainerGraphic(); }
      static DBGraphic makeGraphic() { return new DBContainerGraphic(); }
    }That is almost certainly NOT what you should do though. Instead of refactoring the whole set of classes, in effect introducing some zillion possible bugs, just use the existing classes and then change them slowly over time.
    The advantage of using the existing classes, is that you are finished the project as soon as you start, like right away.
    Andrew

  • Inheritance constructor question

    Hi
    I am having trouble understanding how the superclasses constructor works in inheritance:
    Please look at the following code:
    public class mySuperClass
         mySuperClass ()
              System.out.println("super1");
    public class myClass extends mySuperClass
         myClass ()
              System.out.println("hello1");
         myClass (int q)
              System.out.println("hello2");
    public static void main(String[] args)
              myClass o = new myClass ();
              myClass o = new myClass (3);
    When I run this program the console results are:
    super1
    hello1
    super1
    hello2
    Why does the constructor of the super class run even when I overload it?
    Thanks
    Aharon

    I think you meant to write "Why does the constructor of the super class run even when I overrideit?"
    And the point is you can't override a constructor (technically, they are not even methods). A constructor in a derived class (MyClass) must call a constructor in its superclass (MySuperClass ). If you do not explicitly call one:
    MyClass (int q) {
        super(...arguments...); // <---
        System.out.println("hello2");
    }There will be an attempt to implicitly to invoke super();

  • Inheritance, abstract and concrete

    Given:
    *abstract public class Foo {
    * protected static int bat;
    * public static int bat() {
    * return bat;
    *public class Bar extends Foo {
    * private static int bat = 5;
    Assuming that you have complete rewrite power over both classes, is there any way to have a situation where:
    * Foo f = new Bar();
    * int x = f.bat();
    will set x == 5 without putting an identical
    * public static int bat() {
    * return bat;
    in every single class that extends Foo?

    It's a complicated situation. I have a large number
    of user-defined classes that are all being stored
    together. I want to be able to pass them to the same
    functions, so I don't have to rewrite the functions a
    dozen times with only the variable class changing, so
    I defined them all as extensions of one abstract
    class, but I also need to be able to tell them apart
    when I need to handle them differently. It seemed to
    me that the best way to do that was by giving each
    different concrete class a distinct id number, that
    the handler can use in the rare cases when it's
    needed. I thought the id should be declared static
    because it belongs to the class, not to individual
    instances of the class. But I want to keep it
    private, so nobody can mess with it, so I also need a
    public function to return it. And since it works
    with a static value, it has to be declared as a
    static function.This sounds wrong.
    If they are user defined classes then it is not possible for you to tell them apart.
    Or your terminology means something different.
    If you are writing a plug in engine where something is added later, then the engine can no rely on anything specific about the plug ins. If it does, they are not plug ins.
    If you need to handle them differently with some common categories of functionality then you should be using interfaces and helper classes.
    Pseudo code would be like this...
          interface CommonStuff
                String getName();
         interface Communications
               boolean sendInfo();
         interface Storage
               boolean storeIt();
        class PlugInEngine
             void process(Object o)
                    if (o instanceof Communications)
                          ((Communications)o).sendInfo();
                    if (o instanceof Storage)
                          ((Communications)o).storeIt();
                    if (o instanceof CommonStuff)
                          log("Finished name=" + ((CommonStuff)o).getName());
        }

  • Inheritance, abstract classes

    Hi peeps!
    There's Train class with collection of RailCar
    RailCar is made up of SleepingCar and SaloonCar
    and OccupiableSpace is made up of Berth and Seat
    *RailCar makes use of OccupiableSpace(Abstract Class)
    Is following hierarchy correct?
    OBJECT
    ^
    |
    Train
    ^
    |
    RailCar (Abstract class)
    ^________ ___________^
    |________ __________ |
    1) SleepingCar 2) SaloonCar (these two classes extends RailCar)
    and for remaining classes
    OBJECT
    ^
    |
    OccupiableClass (Abstract Class)
    ^ __________ ____ ^
    | ______________ |
    1)Seat 2) Berth (these two classes extends OccupiableSpace)

    I don't think you need to that abstract here to create a Train class
    is a - the class is extended
    has a - the class has members to reflect the data you wish to store for the class operations (methods) that will act upon that data
    RailCar.class // does not have to be abstract unless you want to defer (or later enforce) some implementations in the subclass
    SleepingCar IS A Carriage
    Carriage HAS A berth
    I think the route 'implements Sleepers' and 'implements Sitters' with an interface for each may give you a more solid design if you want some abstraction in your model.

  • An "abstract" question :-)

    Hello friends
    What's the best Layout in a Content pane?
    I've compined various of them but my Interface does not seem very stable for example when i'm inputting text in the text fields the JLAbels seemed to be moved.
    Is there any Standard to follow for start ?
    thanks.

    So it's a matter of experience.
    I'll do my best.

  • Inheritance Design Question

    I am having a problem of having a problem of how I can go about creating the correct class type. I am reading from a file and the first word in each line is the name of the class I want to create an instance of. And I don't know how I can create an instance of that class by just knowing the class name. I mean I can create the correct class but I don't know how to cast it to the correct type once it is reaturned. Here is my structure of the classes I am talking about.
    public class Segment{]
    public class ISA extends Segment{
      public void setRef01(){ }
      public void setRef02(){ }
      public void setRef03(){ }
      public void setRef04(){ }
    public class IEA extends Segment{
      public void setRef01(){ }
      public void setRef02(){ }
      public void setRef03(){ }
    FileReader reader = new FileReader("myfile.txt");
    String str;
    while((str = reader.readLine()) != null){
      String className = str.substring(0, str.indexOf(" ")).trim();
      Segment seg = getNewSegment(className);
      /*How do I cast it to be of type className either IEA or ISA?
       *I reason is because I need to be able to call setRef04() and
       *I cannot do that b/c it is of the parent type, Segment
    public Segment getNewSegement(String className){
       if(className.equals("ISA"){
         return new ISA();
       }else if( className.equals("IEA"){
         return new IEA();
       }else{
         throw new RuntimeException("Class could not be determined");
    }Any Ideas?
    TIA,
    Doopsterus

    I am confused about class casting. Can you please explain? Also the problem is that since I am going to be calling setRef01 ... setRef02 ... ect depending on the type of object I will have to be constructing the name of the function to call so the sample code would be
                   String segStr = mybuf.substring(0, mybuf.indexOf("|") );
                   String[] tokens = segStr.split("~");
                   Object segment;
                   for(int i = 0; i < tokens.length; i++){
                        if(i == 0){
                             segment = SegmentGetter.getSegmentInstance(tokens);
                             //how do I cast it to the correct type?
                             segment.setSegmentName(tokens[i]);
                        //get the referenceNo
                        String refno;
                        if(i < 10){
                             refno = Segment.getReferenceNo("0"+i);
                        }else{
                             refno = Segment.getReferenceNo(i+"");
                        String functionName = "setRef"+refno;
                        //this does not work... how can I make it work?
                        segment.functionName( tokens[i]);
                   }//end for loop

  • Inheritance/Overriding question

    Morning :)
    Here is my situation. I have the following situation, within the same package
    Class C, with a protected method doStuff(int x), and a public startStuff() method. This startStuff method calls the doStuff method.
    Class IC, which extends C, which also has a separate protected doStuff(int x) method, and a public startStuff() method
    I am instantiating an object of class IC, and calling the startStuff method, which first calls super.startStuff(), which in turn (in my mind) should call the doStuff method within Class C, but it isn't. In the stack trace, I can see Class C.startStuff being called, but when it gets to the doStuff method, it invokes the one in class IC, which isn't what I want.
    Any way for me to fix this, or am I going about it all wrong?

    I think you are talking about something like this :
    public class SuperClass
         protected void doStuff()
              System.out.println("doStuff in SuperClass");
         public void startStuff()
              System.out.println("startStuff in SuperClass");
              doStuff();
    public class SubClass extends SuperClass
         protected void doStuff()
              System.out.println("doStuff in SubClass");
         public void startStuff()
             super.startStuff();
              System.out.println("startStuff in SubClass");
         public static void main(String args[])
              SubClass aSubClass=new SubClass();
              System.out.println("This is main ");
              aSubClass.startStuff();          
    }What is happening here (why doStuff() in SubClass is getting invoked)is as follows:
    We invoke any method on a target reference(i.e.aSubClass.startStuff()),the invoked method has a reference to the target object so that it may refer to the invoking(or target )object during the execution of the program.That reference is represented by this.
    In method overriding the instance method is chosen according to the runtime class of the object referred to by this.So during the execution of statrStuff() in SuperClass , the doStuff() is invoked on the this reference that is the actual run time type of the target object i.e. SubClass.
    That's why doStuff() in SubClass is getting invoked.
    If you want to invoke SuperClass.doStuff(),declare doStuff() as class method (Static) in both the classes.The class methods are not invoked by the runtime class of the object,because these are not related with any instance od a class.

  • A qestion about abstract class

    Dear friends!
    I have follow simple code:
    abstract class Aclass {
    abstract void method1();     
    class Bclass extends Aclass {
    public void method1(String s){
    // implementation
    As I understand I can overload the method "method1" but I got an error.
    So what should I do?
    Thanks

    As I understand I can overload the method "method1"
    but I got an error.
    So what should I do?First of all, whenever you are getting an error and you ask a question here about that error, you should tell us what the error is - most of the tim, you won't get a useful answer if we have to guess what your problem is. Also, when posting code, please use the forum's [code]...[[b]code] formatting tags (see the "special tokens" link when posting a message - you are much more likely to get a useful response if we can read your code - many people will just ignore your question if it is not easy to read.
    Having said that, I'll hazard a guess that the error you are getting is somewhere along the lines of "Class Bclass must implement the inherited abstract method method1()". If so, then that is what you should do - implement amethod called method1 in class Bclass, that takes no arguments.
    Yes, you can overload method1, but you have then implemented an entirely different method - you must supply a no-args version as well.

Maybe you are looking for

  • SAP B1 Patch 42 GUI, Vista SLOW MOTION

    Hi, I just don't know if I'm alone with this. I didn't find any thread about it. I've successfuly installed SAP B1 2005A SP001, Patch 42 on Windows Vista Home Premium.  Everything works find Except When windows pop, its slow like hell.  You know this

  • What was the error and how i remove (using Tomcat)

    HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution threw an exception root cause javax.xm

  • "locking" style definitions

    I have modified and created several styles in Pages documents. Is there a way to keep these styles from being modified? I want to make sure that my bumbling, yet well intentioned and charming office staff doesn't change the formatting in the styles w

  • Item Merging

    Is there any functionality for merging two items if so then how it can be achieved. I have seen Item Relationships but its not working?

  • ORA-00119&ORA-00132

    Hi experts, Till yesterday the database runs fine but today it throws error as, #sqlplus sys/pass as sysdba Connected to Idle instance. sql>startup ORA-00119: invalid specification for system parameter LOCAL_LISTENER ORA-00132: syntax error or unreso