Z
Zeng
From the below situation, it's painful to keep declaring and implement the
similar methods just different return type for each list class;
alternatively, we can just force the client code use RecordBaseList's
methods directly and converting the return object to the correct type on its
own (from RecordBase to RecordTypeA or RecordTypeB)- which is also painful.
Any experienced OO designer out there that can suggest me a better design?
Thank you very much in advance....
abstract class RecordBase
{
abstract public int commonF1();
abstract public int commonF2();
}
public class RecordTypeA : RecordBase
{
override int commonF1() {...}
override int commonF2() {...}
public int FooA() {...}
}
public class RecordTypeB : RecordBase
{
override int commonF1() {...}
override int commonF2() {...}
public int FooB() {}
}
abstract class RecordBaseList
{
public RecordBase FindRecord( int id ) {...}
public RecordBase AddNewRecord() {...}
public RecordBase FirstRecord() {...}
...
...
}
public class RecordTypeAList : RecordBaseList
{
new public RecordTypeA FindRecord( int id ) // we are hiding the method
of base class here
{
return (RecordTypeA) base.FindRecord( id );
}
new public RecordTypeA AddNewRecord() // we are hiding the method of
base class here
{
return (RecordTypeA) base.AddNewRecord( id );
}
new public RecordTypeA FirstRecordRecord() // we are hiding the method
of base class here
{
return (RecordTypeA) base.AddNewRecord( id );
}
}
//// FOR RecordTypeBList, WE WOULD SIMILAR CODE AS RecordTypeAList, JUST
DIFFERENT RETURN TYPE AND TYPE CONVERSION AT RETURN STATEMENT.
similar methods just different return type for each list class;
alternatively, we can just force the client code use RecordBaseList's
methods directly and converting the return object to the correct type on its
own (from RecordBase to RecordTypeA or RecordTypeB)- which is also painful.
Any experienced OO designer out there that can suggest me a better design?
Thank you very much in advance....
abstract class RecordBase
{
abstract public int commonF1();
abstract public int commonF2();
}
public class RecordTypeA : RecordBase
{
override int commonF1() {...}
override int commonF2() {...}
public int FooA() {...}
}
public class RecordTypeB : RecordBase
{
override int commonF1() {...}
override int commonF2() {...}
public int FooB() {}
}
abstract class RecordBaseList
{
public RecordBase FindRecord( int id ) {...}
public RecordBase AddNewRecord() {...}
public RecordBase FirstRecord() {...}
...
...
}
public class RecordTypeAList : RecordBaseList
{
new public RecordTypeA FindRecord( int id ) // we are hiding the method
of base class here
{
return (RecordTypeA) base.FindRecord( id );
}
new public RecordTypeA AddNewRecord() // we are hiding the method of
base class here
{
return (RecordTypeA) base.AddNewRecord( id );
}
new public RecordTypeA FirstRecordRecord() // we are hiding the method
of base class here
{
return (RecordTypeA) base.AddNewRecord( id );
}
}
//// FOR RecordTypeBList, WE WOULD SIMILAR CODE AS RecordTypeAList, JUST
DIFFERENT RETURN TYPE AND TYPE CONVERSION AT RETURN STATEMENT.