0
public class Table{

private String column[];
private String dataType[];
private boolean PK[];
private boolean NN[];
 private int count;
public Table()
{
    count =0;
}

public void AddColumn(String name,String dtype,boolean pk,boolean nn)
{

     column[count]=name;
     dataType[count]=dtype;
     PK[count]=pk;
     NN[count]=nn;
     count++;
} 


 public void Display(Table T)
 {

 }  

 public void DeleteColumn(String name)
{
  if(count==0){return;}
  else if(count ==1)
  {
      if(name==column[0])
         column[0]=null;
         dataType[0]=null;
        count--;
         return;
  }

  else 

  for(int i=0;i<count;i++)
  {
      if(name==column[i])
      {
          column[i]=column[count-1];
          dataType[i]=dataType[count-1];
          PK[i]=PK[count-1];
          NN[i]=NN[count-1];  
      }
  }


 }

这是我的餐桌课;当我设计实体表并保持列名称数据类型等时。这个类及其私有属性是否正确,或者我应该将其分解为更多类,例如属性。

4

1 回答 1

0

我认为您应该创建Column课程。

我会这样做(当然可以做得更好):

public class DataType {
    public static String DATA_TYPE_1 = "dataType1";
    public static String DATA_TYPE_2 = "dataType2";
    public static String DATA_TYPE_3 = "dataType3";
}

public class Column() {
    private String name;
    private DataType dataType;
    private boolean PK;
    private boolean NN;

    // getters and setters
}

public class Table {
    private ArrayList<Column> columns;

    public Table() {
        columns = new ArrayList<Column>();
    }

    public boolean AddColumn(Column column) {
        columns.add(column);
    }

    public boolean DeleteColumn(String name) {
        for (Column c : columns) {
            if (c.getName().equals(name)) {
                return columns.remove(column);
            }
        }
        return false;
    }
}
于 2013-04-08T15:43:59.463 回答