inheritance - Which would be the best design pattern in Java for this problem? -


I have a class CommonTableModel which has several example methods and works on every two example variables

  • Data
  • Data

    Now, I have six tables, each is different in the name of the column, all the normal The methods should be with the CommonTableModel class. Therefore, to give an example of CommonTableModel for a JTable example, I must first start both the frequency variable (column name and data).

    Q1. Do I want to make six tablesmodel, be consistent with each table, and then spread them to normaltablesmodel?

      Public class FirstTemplatesModel generallyModel {Public FirstTableModel () {columnNames = {"id", "name"}; Data = {{1, "John"}}; }}  

    In the above example, I tried to introduce inherited data members so that six tablemodels could populate each column names according to the table they show.

    But I got an error which is prohibiting me from initiating the members who are coming in this way. I think we can not initialize the example variable in this way.

    Then how can I populate the instance variable of the CommonTelLodal so that I can populate those data later in the normal table modeling procedure.

    One of the solutions is to pass data to the constructor of CommonTableModel, but in this way, when I create a table, I have to fill in each column name.

    I am very confused because I do not have much experience in programming and do not know good coding practices.

    Please also mention some good design pattern books so that I get a better understanding of design patterns.

  • But I got an error that would allow me to initiate the inherited members To this side is banned. I think we can not initialize the example variable in this way.

    The ARARs that are not started with new are array constants . After the announcement, you can start them only directly e.g.

      string [] strings = {"foo", "bar"}; In this way, you should replace special rows (assuming they are already the  protected  fields of  CommonTableModel ): 

      columnNames = new string [] {"id", "name"}; Data = new object [] [] {{1, "John"}}; According to the comments,  

    edit : You can definitely define a constructor for it and call super Can be used . The advantage of this is that it improves the degree of encapsulation, i.e. you do not need to declare the protected field, but now they can be declared as private here The kickoff example is:

      public intangible class CommonTableModel {personal string} [columnNames; Private object [] [] data; Protected CommonTableModel (string [] columnname, object [] [] data) {this.columnNames = columnNames; This.data = data; The public class extends to the FirstTableModel Moderate Model (public FirstTableModel ()) {super (new string) ["id", "name"}, new object [] [] {{1, "John"}}); }}  

    Note that you still need the new keyword to give them a code (rsp was wrong in its reply). You should only make No properties stable ! This will affect every instance of the same category. You do not really want to do this here also see my comment below.


    Comments

    Popular posts from this blog

    sql - dynamically varied number of conditions in the 'where' statement using LINQ -

    asp.net mvc - Dynamically Generated Ajax.BeginForm -

    Debug on symbian -