I am relatively new to class design and I have a task that I'm not sure how best to complete, or whether my idea in general is a code smell.
I'm developing a RPG where people can own monsters, so each one is an object instance of the Monster class. Since the sprite of a monster changes depending on a few different factors, the Monster class has a method for drawing the sprite that I call which does all the checks and logic and displays the correct sprite using the object's properties and I just call it like:
This method does checks using other class methods, such as
which checks data from the database using a unique monster ID (a class property) and stored as object properties.
Now and then for the story and in other places, I want to draw a monster sprite that isn't actually owned by anyone, so has no database row or object instance. Rather than hardcode the image URL or duplicate my code, is there any way a method can be called both as part of an instance and statically and respond accordingly? Is this even a good idea?
So in my head I could do:
This will use the instance properties to determine all the necessary logic to display the sprite, or I could do:
To draw a monster sprite without relying on class properties. Maybe I could pass an array as an argument for all the necessary object property checks the method usually relies on.
I imagine I could do something using func_get_args() or lots of conditionals but I could see that turning into spaghetti code quickly. Is this a good idea, or is it even possible? I'm specifically referring to PHP with this question.