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

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.
 
J

Jeff Louie

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top