How to design the class architectures if the classes have some save functions?

  • Thread starter Thread starter Quentin Huo
  • Start date Start date
Q

Quentin Huo

Hi:

I have several classes and they have some same common functions like write a
property value to a text file, or read from the file to a property. I did as
followed:

I created an abstract class and all the other classes inherit from it. In
the abstract class, I made several protected methods (not abstract methods)
and implemented the common functions. So, the sub classes will have the same
functions working on the their properties.

Any problem or any suggestion?

Thanks

Q.
 
Quentin... Probably, but without knowing the specifics it is not
possible to
say. In general the sub classes should represent specializations of the
base
class and should expand, but not restrict the behaviour of the base
class.
Specifically, a class hierarchy should be designed such that the
behavior of
the base class holds for all subclasses of the class.

http://c2.com/cgi/wiki?LiskovSubstitutionPrinciple

Regards,
Jeff
I created an abstract class and all the other classes inherit from it.
In
the abstract class, I made several protected methods (not abstract
methods)
and implemented the common functions. So, the sub classes will have the
same functions working on the their properties.
 
Back
Top