开发者

Extending a class with common functionality

I have three classes which basically do very similar things;

  1. Store a record of an uploaded file.
  2. Move and upload the file.
  3. Set the status of the record to active or revoked.

One of the classes has an additional update method. Each class references a different table in the database because although some of the fields are common, there are a couple of fields extra 开发者_运维技巧in some of the tables.

As quite a lot of the functionality is common I think it may be best to extend a base class rather than duplicating a lot of the functionality.

My only quarrel is the construct function on the base class. As some of the fields in each table are additional I'm concerned this will prevent a base class.

I have thought of using an abstract class as this will allow me to extend on functionality whilst maintaining most of the things in one place. But it's the problem with the construct. Can I have an abstract class with no construct?

Any ideas?


If I understand you: You can have any class without __construct(). And you can always overwrite every method (except methods, that are declared as final) of a parent class in a child class.


I am sorry but I guess I do not completely understand your question. Anyway in inherited class you can always override the constructor and within it invoke the superclass constructor plus further stuff if needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜