Reputation: 137
my query is about architecture and relation of classes, I would like to know better solution than I have implemented.
I have 4 classes , explaining one line for each
Now come to general script which will use all 4 classes. so I am not understanding which class will extend which another class
No relation between A.php and B.php
But x.php must use all 3 classes core.php, A.php and B.php.
currently what I have done , I design one interface for core class, and x.php extend core class and implement interface. I design A.php and B.php as static classes.
Please guide
Upvotes: 0
Views: 160
Reputation: 1094
This sounds like basic dependency management. I don't understand why you explicitly want to extend anything though?
What you probably should do instead is inject the needed dependencies. Instantiate Core
, A
and B
separately before instantiating X
with the objects it's dependent on.
Upvotes: 0
Reputation: 522626
You don't have to extend
classes if they have nothing to do with each other. You can simply use one class inside another without those two having any relationship inheritance or interface-wise.
You may structure it like this:
class Common
is your base class that every class inherits from and contains common code that all classes need, say code for logging or database access.class A extends Common
and is specialized for some CSV-related tasks. This class may or may not actually do anything by itself.class B extends A
and is even more specialized to some specific task involving CSV.class X extends Common
and is again some other task.Generally, if a class does almost the same but slightly more specialized or differently, extend
a common base class. If a class has nothing at all in common with another, just make them standalone classes. Use interfaces
for polymorphism; it doesn't sound like that's what you need right now.
Upvotes: 2