0

I am creating a system which manages projects. Each projects' behaviour can be customized by custom PHP class called c11n, that the project's owner can create by extending my parent c11nBase class. It works well when handling single project at a time (in my code) but once I started creating a script that works with multiple projects at once, the classnames start to clash - because each child class is called c11n.

How to go around this? Is there a better pattern for behaviour custimization using child classes?

I can of course make sure, that each child class is named differently e.g. project1c11n extends c11nBase, project2c11n extends c11nBase etc. but I don't want to keep track of the classnames somewhere else, I want everything to be encapsulated in the customization file. I would need something like "instantiate the single class defined in that file".

6
  • The closest I have got so far is to have different c11n child class names which would be the same as their containing file's name, from which I can drive the class name... but it feels a little brittle. Commented May 4, 2024 at 1:05
  • Can you use an interface for this? Commented May 4, 2024 at 1:39
  • And there’s also namespaces. Honestly, if you have a config file then I don’t know why a class’s name would matter Commented May 4, 2024 at 12:28
  • The class name matters because I have to instantiate the c11n class that the project owner supplies. Namespaces does not solve the issue because how would I know the name of that namespace. Commented May 4, 2024 at 13:24
  • If they supply it, can’t they tell you what it is then? Same with namespace. And you can prescribe the latter. “Project XYZ, put your code in Projects\XYZ Commented May 4, 2024 at 13:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.