Correct Implementation of Virtual Functions in PHP?

前端 未结 3 1011
臣服心动
臣服心动 2021-02-12 10:42

at my working place (php only) we have a base class for database abstraction. When you want to add a new database table to the base layer, you have to create a subclass of this

3条回答
  •  野的像风
    2021-02-12 11:25

    Without an example of the implementation of your base class, it's hard to give concrete info. But a few things come to mind:

    1. Database abstraction is complex stuff to begin with. I understand that you want to keep it lean, clean and mean, but I think it's pretty darn difficult. You really have to take a thorough look at the specs of different DB engines to see what parts are general and what parts need specialization. Also; are you sure you don't have DB abstraction mixed up with the Table Data Gateway pattern, as you are talking about adding DB tables by extending the base class?

    2. The methods of your current base class might be doing too much and/or are not general enough to begin with, if the extended classes are bending over backwards too keep it clean. Maybe you should break the base class interface methods up in smaller protected methods that are general enough to be reused in the overriding methods of the extended classes? Or vice versa: maybe you should have hooks to overridable methods in your interface methods.

    3. Following from point 2: What's wrong with having an abstract class with some general implemented methods, and let your vanilla class (your base class) and other classes inherit from that?

    4. Lastly, maybe you should just enforce an interface to be implemented, in stead of extending the base class?

提交回复
热议问题