Multiple inheriting class names versus single and selective include
At the moment I essentially have:
A.php: class A { ... }
A1.php: class A1 extends A { A1 stuff... }
A2.php: class A2 extends A { A2 stuff... }
...
factory.php: create($obj) {return new $obj;}
I'm thinking of changing it to:
A.php: class A { ... }
A1.php: class B extends A { A1 stuff... }
A2.php: class B extends A { A2 stuff... }
...
factory.php: create($obj) { require ($obj.".ph开发者_如何转开发p"); return new B; }
Any comments, or dangers that lie ahead? Only one class will ever get instantiated per PHP session.
My first impressions:
- You can never load both classes into memory at once. Even if you don't usually do this, it'll make, for example, unit testing hard.
- Debugging is made harder if your debugger tells you there's a problem with class
B
, but not which classB
. - A class describes a logical unit. There shouldn't be two logical units with the same name but different functionality.
精彩评论