Abstraction problem

I'm trying to develop a CommandFactory that can, given a known set of parameters, instantiate one Command in a dynamic set of Commands.
class CommandFactory
  Hashtable commandKeys;
  private static CommandFactory instance = null;
  private CommandFactory()
    //code that initializes and populates commandKeys
  public static CommandFactory getInstance()
    if( instance == null ) instance = new CommandFactory();
  public Command parse( String cmd )
    String key = cmd.substring(0,cmd.indexOf(" "));
    String cmd_parms = cmd.substring( cmd.indexOf(" ")+1 );
    Method m = (Method)commandKeys.get(key);
    return (Command) m.invoke( null, new Object[] { cmd_parms } );
public abstract class Command
  public abstract execute();
}Now, I'd like to be able to know at compile time that every sub-class of Command has a static method defined such as:
//adding to my above Command a bit
abstract class Command
  public abstract void execute();
  public abstract static Command parse( String cmd );
class CommandSubclass
  public void execute()
    //do something
  public static Command parse( String cmd )
    //does something
   return newCommand;
}The closest thing I can think of to naming what I want here is an abstract static method. That way at compile-time I know with certainty that the Command subclasses have the proper tidbits to initialize and give me back a Command.
Now, I know that Java does not support abstract static methods. And what I've done instead is just assume that my various Command classes have the "parse" static method. But I run the risk of not knowing until run-time that a Command subclass does not have the needed static method.
Essentially, I need a means to enforce a uniform way of initializing subclasses of an abstract superclass. Anyone know how to get that other than reflection, hoping, and praying? Or, is there a different pattern I should be using here?
Thanks,
--mb

It removes the ability of the Factory to say what it should/should not have. No, an interface places no such restriction. What you have is three different problems:
1/how to delegate the instantiation of command objects to command specific mappings.
2/how to load the mappings of command names to the instantiation mechanism at runtime
and now you have
3/ the factory to have a say in what mappings it will support.
1/ is handled perfectly well using interfaces and registry/delegate factory objects; it's convienent to implement these factories as command prototypes, but not necessary, hence there are separate factory and command interfaces.
2/ would be handled by loading the mappings from some data source together with an expression for instantiting the factory instances, together with a controlling registry factory that delegates to the specific factories. One mechanism for this is java.beans.XMLEncoder, or you can hand craft your own restricted version using Class.forName().newInstance. In the above example I didn't do this for you, and created the registry as part of initialising the application.
3/ you've just introduced and you haven't specified what more control you want inside the factory-registery that 1 + 2 don't give you.
I already have the mechanism of telling the Factory what factories it should use to build it's look-up table.So use that mechanism to populate the registry, instead of the test code above.
I suppose an alternative is to have the Factory act as a kind of security manager. This seems to be extra to the previous requirements; what do you want it to do as well as being a factory?
As CommandFactory subclasses are loaded, they create an instance of them, and attempt to register with the top-level CommandFactory to build a look-up or chain of responsibility -- just like your static block. Yes. Though typically I'd use a more flexible mechanism, so that you can load the class without it registering. The static block above in is the class that sets up the application, not the class that implements CommandFactory. If you put the registration code there, then you are forced to have a singleton registry and it becomes tightly bound to one use pattern, and hard to maintain.
Also, when the CommandFactory is instantiated, it can forName all the classes it knows it's looking for to ensure they are loaded.They will be loaded when you create an instance to register. You don't need to do any extra calls to forName. You can use the forName to implement the creation of an instance to register, or you can use the more flexible mechanism built into XmlEncoder. Don't rely on subclasses implementing a particualar registration mechanism, but separate that to a different place. So the only thing that a correct implementation of CommandFactory does is implement a method that creates a command. That way, everything is part of the contract.
...but isn't it bad coding practice to initialize in static code blocks?No. They exist exactly for the purpose of initialising static state; you just have to ensure you don't throw any exceptions and are aware of load-order dependencies. They're also useful for throwaway stuff like the example above, where you want to set up global state for tests rather than writing a full application. But don't use them to do things which are not required to load the class- there's a very big difference between flow of control in the code above and:class EchoCommand extends PrototypeCommand {
  public void execute () {
    System.out.println(args);
  static {
    MB10Command.register.register("echo", new EchoCommand());
class SortCommand extends PrototypeCommand {
  public void execute () {
    List sort = new ArrayList(args);
    Collections.sort(sort);
    System.out.println(sort);
  static {
    MB10Command.register.register("sort", new SortCommand());
public class MB10Command {
  static CommandRegister register = new CommandRegister();
  static {
    new EchoCommand();
    new SortCommand();
  public static void main (String[] args) {
    register.parse(args).execute();
}Because EchoCommand is tied to one particular global registry, it's unusable in any other context, and you end up thinking about adding extra code to overcome the hard coded global variable (otherwise known as singleton anti-pattern).
You also lose the expression of intent- in the previous code, when you load the main class, you explicitly create a registry, then register a couple of prototypes with it. If you start using static blocks so that a side-effect of loading a class is that it registers a prototype with a third party, and then use Class.forName so that registration is a side-effect of a side-effect, you will get very confused very rapidly. Keep both implementation and state as local as possible.
Pete

Similar Messages

  • Abstract problem

    Could anyone help me? I created hierachical "SuperClass" and "FinalClass" classes as shown below. When I try to compile an application "Test.java" which accesses aforementioned classes, compiler can recognize the superclass but not the subclass. Both of the ".class" reside in one directory and I am compiling an application from the same directory. How do I correct this problem?
    //Super Class
    public abstract class SuperClass {
      private String firstName;
      private String lastName;
      public SuperClass(String first, String last)
         firstName = first;
         lastName = last;
      public String getFirstName()
      { return firstName; }
      public String getLastName()
      { return lastName; }
      public String toString()
      { return firstName + lastName; }
      public abstract double hourlyRate();
    //Final Class
    public final class FinalClass {
      private double rate;
      public FinalClass(String first, String last,
                        double r)
         super(first, last);
         setHourlyRate(r);
      public void setHourlyRate(double r)
      { hourlyRate = (r > 0 ? r : 0); }
      public double hourlyRate()
      { return hourlyRate; }
    //Test Super and Final Classes
    import javax.swing.JOptionPane;
    import java.text.DecimalFormat;
    public class Test {
      public static void main(String args[])
         Super ref;    // referencing Super class
         FinalClass f; // referencing Final classI get the following compiler error.
    Test.java:nn: cannot resolve symbol:
    symbol : class FinalClass
    location: class Test
    FinalClass f;
    ^

    Alphard,
    Your FinalClass shouldn't be compiling, according to the code you provided, for the following reasons:
    1. The constructor of the FinalClass tries to call the constructor of the SuperClass. However, your FinalClass is not inheriting from anything. You need to provide the extends SuperClass in your FinalClass declaration: public final class FinalClass extends SuperClass {2. The variable hourlyRate has not been declared anywhere in FinalClass. I think you want it to be your data member 'rate'. Let's change the data member to hourlyRate.
    I have modified your FinalClass. The code follows:
    //Final Class
    public final class FinalClass extends SuperClass {
       private double hourlyRate;
       public FinalClass(String first, String last, double r) {
         super(first, last);
         setHourlyRate(r);
       public void setHourlyRate(double r)
       { hourlyRate = (r > 0 ? r : 0); }
       public double hourlyRate()
       { return hourlyRate; }
    }Your Test class should work after you make these changes to your FinalClass.
    TJJ

  • Abstract/ concrete class questions/problems

    I am new to java and working on a abstract problem. I'm getting several errors. Here is the code I have so far for the abstract class. I commented out the super and it compiles but I'm not sure if it correct. I'm suppose to create a abstract base class Animal. Single constructor requires String to indicate type of animal which then is stored in an instance variable. I also have to add a few methods (describe(), move(), etc).
    public abstract class  Animal
         public Animal(String type)
              //super(type);
         public abstract String describe();
         public abstract String sound();
         public abstract String sleep();
         public abstract String move();
    }

    thanks for the replies. I modified my code but I have a few more errors I can't figure out. Can you browse the code and help point me in the right direction.
    Here are the errors I get
    cannot find symbol
    symbol : constructor Cat(java.lang.String,java.lang.String)
    location: class Cat
    cannot find symbol
    symbol : constructor Robin(java.lang.String)
    location: class Robin
    abstract base class:
    public abstract class  Animal
         String type;
         public Animal(String type)
           this.type = type;
         public abstract String describe();
         public abstract String sound();
         public abstract String sleep();
         public abstract String move();
    }concrete class
    public class Cat extends Animal
         private String name;
         protected String breed;
         public Cat()
           super("Cat");
         public String describe()
              return new String(",a breed of Cat called");
         public String sound()
              return new String("Meow");
         public String sleep()
              return new String("Kitty is having purfect dreams!");
         public String move()
              return new String("This little Kitty moves fast!");
    }another abstract class
    public abstract class Bird extends Animal
         protected String breed;
         public Bird()
           super("Bird");
         public abstract String move();
    }here is the abstract test program itself
    public class AbstractTest
         public static void main(String[] args)
              Cat cat = new Cat("Kitty", "Angora");
              Robin bird = new Robin("Rockin");
              System.out.println("Form the cat:   ");
              System.out.print("This is:     "); cat.describe();
              System.out.print("Sound:       "); cat.sound();
              System.out.print("Sleeping:    "); cat.sleep();
              System.out.print("Moving:      "); cat.move();
              System.out.println("\n");
              System.out.println("For the robin:     "); bird.describe();
              System.out.print("This is:             "); bird.sound();
              System.out.print("Sound:               "); bird.sleep();
              System.out.print("Moving:              "); bird.move();
              System.out.print("\n");
              System.out.println("nEnd of program.");
    }

  • My computer has some serious problems, my iphoto only shows thumb size pics when I try to open them, i tried to rebuild my files from folders that had the pics in them. originally all the photos has a large delta with a question mark. also I can't back up

    my computer has some serious problems, my iphoto only shows  only shows thumb size pics when I try to open them, i tried to rebuild my files from folders that had the pics in them. originally all the photos had a large delta with a question mark. also I can't back up the library file because its not there. I went to time machune and tried to find the file but I can't find it or I am looking in the wrong place. I also lost my Idvd file, only have broken chain showing.

    Details please
    What version of iPhoto and of the OS?
    i tried to rebuild my files from folders that had the pics in them.
    Exactly what did you do and how did you do it? this ay be the cause of your issue but without details we can n=ony guess
    my iphoto only shows  only shows thumb size pics when I try to open them,
    where do you see htis? In the iPhoto window? what does "try to pen them" exactly mean?
    originally all the photos had a large delta with a question mark.
    Ok - this usually has a simple solution - do you still have a copy of the library that has this problem?
    also I can't back up the library file because its not there.
    This makes no sense at all - all of your previous statements indicate that you do have an iPhoto library but have some problems with it
    By default your iPHoto library is located in your Pictures folder and is named iPhtoo library - if tha tis not the case the you have moved or renamed it and only you know what you did until you tell us the details
    I went to time machune and tried to find the file but I can't find it or I am looking in the wrong place.
    Again unless you actually share what and how you are doing thing but continue to simply state abstract problems it is no possible to assist you - details on using Time Machine are here  --  http://support.apple.com/kb/HT1427?viewlocale=en_US&locale=en_US   --     and   --    http://pondini.org/TM/FAQ.html   ---
    I also lost my Idvd file, only have broken chain showing.
    This would be better addressed in the iDVD forum - but again unlesss yu share detailed information no one can assist
    LN

  • Abstract methods probe!!!!!!

    HI,
    Please help me,
    I would like to make changeSize abstract
    Problem is subclass Circle AND Triangle
    where Circle requiers only one parameter (radius)
    and Triangle (two height & width)
    abstract public void changeSize(int newSize);
    Thanks //jF

    I suspect something's severly wrong here ... although
    you unify the parameter
    passing (using double[]s) if feel (I'm psychic
    remember?) that you're still violating
    the LSP. IMHO resizing using one parameter versus
    resizing using two parameters
    are two different things and can't be unified using
    polymorphism (the abstract method
    in the base class).
    Maybe there should be two abstract resize methods
    in the base class. All
    subclasses are to decide for themselves what to do
    given any of the two ...The basic problem is that circles and triangles don't have too much in common to model a good inheritance tree...

  • I cant seem to get iphoto to work

    HI i needed to download i photo but i cant seem to open in after downloading the i photo library

    Can't read your mind and stating an abstract problem gives us nothing to work with
    What version of iPhoto? Of the OS? what has recently changed?
    To download iPhoto backup up your iphoto library and download from the App store
    To open it click on it in the Dock
    You can not "download" the iphoto library - it is only local to you - the Application is downloadable - the library is yours
    LN

  • IPhoto cannot export video after installing Yosemite, HELP. It happens to my 2 MacBook Pros, 2 Airs and iMac.

    iPhoto cannot export video after installing Yosemite.

    You have a problem and yo need to solve it
    If you want help you need to do more than state an abstract problem - we need details - what can't it? what makes you thing it can't? what errors occur? what are the symptoms?
    Your post is like "my car won't start" - with no details it could be anything from having lost the key to gas - you have to provie details
    LN

  • Simple Page Structure with DynNavigation and ContentPages - Best Practise??

    Hi ...
    actually I am going to develop a simple JSF Application(my first) :-|
    Simple Description
    User logs in - next View(JSF Page) consists an user(rigths spezific)menu and a content part witch consists of formbased use cases which have to be solved by the application. The parts for its own is not my problem. But how to bring them together ...
    Question
    I am looking for a best practise Solution for the described problem. Which tag/technology I should use. Is it possible to solve this problem by simple using JSF or am I forced to use MyFaces, Tiles or somthing else ...
    I think this is normal use of JSF or am I wrong with that. I am reading several tutorials but did not find a solution for this global / abstract problem.
    I hope my "english" is readable :)) thanks in advance

    Connect the phone to the PC. Open the folder you want to copy using windows explorer. Copy music files. Right click & select send to Windows Phone. For help regarding Playlists go to the link below:
    Playlist WP8
    Please mark the post as solution if it solves your problem.
    Current Device - Nokia Lumia 1020/920

  • Why won't iPhoto download after i have bought it from the app store and installed mavericks

    why won't iPhoto download after i have bought it from the app store and installed mavericks?

    Sorry no mind readers here so you have to tell us details, context and any error messages - just stating an abstract problem that could have thousands of causes is not enough
    What version of iPhoto? Of the OS? what has changed since it worked? How are you trying to open it (clicking on the icon in the Dock, double clicking on the application in the applications folder, ???)?
    Anything else you can tell a total stranger who can not see you or your computer to let them assist you?
    LN

  • Putting files from folders puts them up in corner,  Lion

    If I open a folder and remove a file to place it somewhere on my desktop, it immediately flies up to the top right corner of my screen, half-way out of view.
    It took me awhile to even discover that's where they went and I kept having to open them with Spotlight.
    Once I delicately pick the file out of the corner with my pointer I can place it wherever I want on the desktop.
    This happens whether I'm using hotcorners or not, no matter what view.
    Anybody else dealing with this? Only since installing Lion...
    Thanks any and everyone!

    Details please
    What version of iPhoto and of the OS?
    i tried to rebuild my files from folders that had the pics in them.
    Exactly what did you do and how did you do it? this ay be the cause of your issue but without details we can n=ony guess
    my iphoto only shows  only shows thumb size pics when I try to open them,
    where do you see htis? In the iPhoto window? what does "try to pen them" exactly mean?
    originally all the photos had a large delta with a question mark.
    Ok - this usually has a simple solution - do you still have a copy of the library that has this problem?
    also I can't back up the library file because its not there.
    This makes no sense at all - all of your previous statements indicate that you do have an iPhoto library but have some problems with it
    By default your iPHoto library is located in your Pictures folder and is named iPhtoo library - if tha tis not the case the you have moved or renamed it and only you know what you did until you tell us the details
    I went to time machune and tried to find the file but I can't find it or I am looking in the wrong place.
    Again unless you actually share what and how you are doing thing but continue to simply state abstract problems it is no possible to assist you - details on using Time Machine are here  --  http://support.apple.com/kb/HT1427?viewlocale=en_US&locale=en_US   --     and   --    http://pondini.org/TM/FAQ.html   ---
    I also lost my Idvd file, only have broken chain showing.
    This would be better addressed in the iDVD forum - but again unlesss yu share detailed information no one can assist
    LN

  • I am unable to download iPhoto to my macbook air

    help

    My car won't start - help
    We ancually need much more than an abstract problem tha tcould have hundreds of causes
    Like what version of iPhoto do you have? What version are you trying to download? What version of the OS do you have? What exact error messages do you get? Why exactly can't you download iPhoto?
    You need to do your share and supply details if you want us to help since we only know what you tell us
    LN

  • Iphoto does not support the resolution of my dslr camera...how do i upload full resolution photos?

    iphoto does not support the resolution of my dslr camera...how do i upload full resolution photos?

    You actually need to give information to get help - just stating an abstract problems (which is most certainly not a problem at all) gives the volunteers hearer nothing to work with to help you
    What version of iPhoto? Of the OS? What exactly is the problem (iPhoto does support the resolution of your camera so that is NOT a problem)? what exactly are you doing? What error messages do you get? why do you incorrectly think that iPhoto does not support full resolution?
    At this time your question is like my car won't start - why not? Could be anything from you did not put the key jun to being out of gas to having the engine stolen - no way to tell anything - except that the problem you claim is not true (at least in my example I would know that the car did not start)
    LN

  • Generating radom data

    Hi all,
    i'm a student in polytechnic in Singapore. i am doing a disc rental project using jcreator right now and is facing some difficulties.
    i need to create a table inside a class with back ground, some lables, a 10 rows table and a generate button. and what this table gotta do is to generate 10 random disc information from my data base. info which include title, cost price etc..depending on the title. and i need to have a button which everytime i click, it will generate another 10 set of random disc info out.
    java experts here, pls help me and advise me! :) speaking the truth, my java is kinda lousy.. haha.
    regards,
    Titus

    Hi all,
    after getting some files from the java web, i managed to make the code out. but in the end i have 3 error which by my weak knowleadge of java, i cant solve it. its about some abstract problem. here is my program:
    import java.sql.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    * TableDemo is just like SimpleTableDemo, except that it
    * uses a custom TableModel.
    public class SearchByRandom extends JPanel {
              ImageIcon background;
              Image backgroundImage;
              private JLabel jLabel1 = null;
              private JButton SearchRandom = null;
         private boolean DEBUG = false;
    public SearchByRandom() {
    super(new GridLayout(1,0));
              background = new ImageIcon("BackGrd.jpg");
    backgroundImage = background.getImage(); // for background image          
    setLayout(null);
    add(jLabel1(), null);     
              add(getSearchByRandom(), null);
    JTable table = new JTable(new MyTableModel()); //error2
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    //table.setFillsViewportHeight(true);
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this panel.
    add(scrollPane);
    class MyTableModel extends AbstractTableModel {  //error1
    private String[] columnNames = {"Disc Title",
    "Disc ID",
    "Status",
    "Type",
    "Discription",
    "Language",
    "Rating",
    "No. of Disc",
    "Cost Price",
    private Object[][] data = {
                   {"Transformers", "M0001", "Available", "Movie", "robots", "English", 6, 2, "$6.00"},
    {"Transformers", "M0001", "Available", "Movie", "robots", "English", 6, 2, "$6.00"},
    {"Transformers", "M0001", "Available", "Movie", "robots", "English", 6, 2, "$6.00"},
    {"Transformers", "M0001", "Available", "Movie", "robots", "English", 6, 2, "$6.00"},
    {"Transformers", "M0001", "Available", "Movie", "robots", "English", 6, 2, "$6.00"},
    {"Transformers", "M0001", "Available", "Movie", "robots", "English", 6, 2, "$6.00"},
    {"Transformers", "M0001", "Available", "Movie", "robots", "English", 6, 2, "$6.00"},
    //all the above info are the same becasuse im just testing the code.
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.length;
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
    return data[row][col];
    * JTable uses this method to determine the default renderer/
    * editor for each cell. If we didn't implement this method,
    * then the last column would contain text ("true"/"false"),
    * rather than a check box.
    public Class getColumnClass(int c) {
    return getValueAt(0, c).getClass();
    * Don't need to implement this method unless your table's
    * editable.
    public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    if (col < 2) {
    return false;
    } else {
    return true;
    * Don't need to implement this method unless your table's
    * data can change.
    public void setValueAt(Object value, int row, int col) {
    if (DEBUG) {
    System.out.println("Setting value at " + row + "," + col
    + " to " + value
    + " (an instance of "
    + value.getClass() + ")");
    data[row][col] = value;
    fireTableCellUpdated(row, col); //error3
    if (DEBUG) {
    System.out.println("New value of data:");
    printDebugData();
    private void printDebugData() {
    int numRows = getRowCount();
    int numCols = getColumnCount();
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + data[i][j]);
    System.out.println();
    System.out.println("--------------------------");
         private JLabel jLabel1(){
         if (jLabel1 == null) {
                   jLabel1 = new JLabel("Search By Random");
                   jLabel1.setBounds(new java.awt.Rectangle(100, 140, 500, 105));
                   jLabel1.setOpaque(false);
                   jLabel1.setFont(new java.awt.Font("Comic Sans MS", 0, 30));
         //jLabel1.setForeground(new java.awt.Color(255, 255, 255));
              return jLabel1;
         private JButton getSearchByRandom() {
              if (SearchRandom == null) {
                   SearchRandom = new JButton("Click here to generate another random list!");
                   SearchRandom.setBounds(new java.awt.Rectangle(100, 400, 280, 30));
                   SearchRandom.setOpaque(false);
                   SearchRandom.setBorder(null);
                   SearchRandom.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             toSearchByRandom(e);
              return SearchRandom;
         public void toSearchByRandom(ActionEvent e){
                   JFrame frame = new JFrame("Search By Random");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setContentPane(new SearchRandom());
              frame.setResizable (false);
                   frame.setSize(800, 600);
                   frame.setLocation(50, 50);
                   frame.setVisible(true);
    public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background
    //Draw image at its natural size first.
    g.drawImage(backgroundImage, 0, 0,800,600, this);
    and my errors are:
    --------------------Configuration: <Default>--------------------
    C:\Users\Titus\Documents\School\IT2292 OOADPJ\Project\Program\SearchByRandom.java:45: cannot find symbol
    symbol : class AbstractTableModel
    location: class SearchByRandom
    class MyTableModel extends AbstractTableModel {
    ^
    C:\Users\Titus\Documents\School\IT2292 OOADPJ\Project\Program\SearchByRandom.java:33: cannot find symbol
    symbol : constructor JTable(SearchByRandom.MyTableModel)
    location: class javax.swing.JTable
    JTable table = new JTable(new MyTableModel());
    ^
    C:\Users\Titus\Documents\School\IT2292 OOADPJ\Project\Program\SearchByRandom.java:119: cannot find symbol
    symbol : method fireTableCellUpdated(int,int)
    location: class SearchByRandom.MyTableModel
    fireTableCellUpdated(row, col);
    ^
    3 errors
    Pls advise. thanks you!!
    Titus

  • Problem compiling Abstract class

    Hi
    I have writting an abstract class Sort.java and another class BubbleSort.java. I am having problems compiling BubbleSort.java class.
    The following is the error message
    BubbleSort.java:8: missing method body, or declare abstract
         public int doSorting(int[] array);
    ^
    BubbleSort.java:11: return outside method
              return num;
    ^
    The following is the code
    public abstract class Sort
    public abstract int doSorting(int[] array);
    }// End of class
    public class BubbleSort extends Sort
    private int num = 2;
    public int doSorting(int[] array);
    num = num + 2;
    return num;
    } // end of class

    Remove the semi-colon.
    public int doSorting(int[] array); // <------- there

  • Abstract Class Problem

    HI, I have 4 classes and the hierarchy of those classes is as follows:
    DBCachedRecord
    |
    ServiceHeader
    |
    ServiceHeader22, ServiceHeader25
    I made ServiceHeader abstract and ServiceHeader22 and ServiceHeader25 need to call constructors of DBCachedRecord. When i do super(..), I got the error Constructor cannot find in ServiceHeader.
    There are few static methods as well in each of the class which I want to access those. And I have a method getService in ServiceHeader which decides which serviceHeader to use (either 22 or 25).
    I found this really a hard one and I cannot find a solution yet. Would anybody help me in resolving this scenario.
    Thanks

    When i do super(..), I got the error
    Constructor cannot find in ServiceHeader.So what is your question? You believe the compiler, right? You need to either add the constructor you want to call, or call a constructor that already exists. Keep in mind the default constructor thing - if you don't know what I'm talking about then that may be the problem.
    There are few static methods as well in each of the
    class which I want to access those. And I have a
    method getService in ServiceHeader which decides which
    serviceHeader to use (either 22 or 25).Generally having a superclass know anything about its subclasses is a bad design. Consider making these methods non-static and overriding them in the subclasses. IMO this is OK to do even if they don't use non-static data, in order to get the appropriate class-specific behavior. Others may disagree though, I don't know.

Maybe you are looking for

  • Invoice Numbers

    Hai, I want to know While doing  Inwarding, Cummercial Invoice number is not being displayed for some of the orders. Why it is happening? Thanks

  • 2 separate itunes accounts for 1 ipod touch

    This is probably not complicated but here is my situation.... My daughter has an ipod touch and always asks me to add movies, games, etc. My ex wife decided that she wanted the itunes account shared with her account and since she won't give me the pa

  • Flash to Jpg

    Hi People !! How can i can to export a flash image to jpeg? Can you help me ? Thanks !! Alessandro

  • When I compose an email and send it goes to my outbox. Why?

    WHen I compose an email and hit the send button, it goes to my outbox. Why?

  • Using a Range Extender with WLC & LWAP

    Hi, is it possible to use a Wireless range extender with a WLAN installation of LWAPs & WLC? Is there a security setting in the WLC that prevents multiple clients connecting through the range extender? Any advise would be appreciated. Regards, Chris