Re: which design pattern suits for minimal changes to happen when an interface method signature is changed.
Posted By:
Shaun_Childers
Posted On:
Tuesday, August 30, 2005 10:05 AM
Another way to handle this is to have an interface that defines your methods you want all objects to implement.
public interface Test {
public long getId();
}
Define and abstract class that has (aside from a default constructor), a constructor that takes in the value:
public abstract class Master {
...
private long pk_id = -1;
...
public Master(long pk_id) {
this.pk_id = pk_id;
}
...
public long getId() {
return this.pk_id;
}
}
Now you can see that any (you mentioned 100) class that extends the Master class will have access to the primary key value regardless of how you set it. In other words, if/when you needed to change this, you would simple change the Master constructor to now accept an Object that contains the primary key and the subclasses would still have access to the primary key value without needing to be modified (via the getId() method. For example:
public Master(Object o) {
this.pk_id = o.getPK();
}