开发者

Multiple inheriting class names versus single and selective include

开发者 https://www.devze.com 2023-03-04 19:55 出处:网络
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... }

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 class B.
  • A class describes a logical unit. There shouldn't be two logical units with the same name but different functionality.
0

精彩评论

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