Let´s say I have two PHP classes one called gallery and one called image.
In the class image I want to include the class gallery, and in the class gallery I want to include the class image.
How could this be properly done – or whats the best way to accomplish this?
What I want to be able to do in the end is to use methods of the class gallery in some methods of the class image.
For example: I have a method “delete” in both classes. In the class gallery the method is used to delete a specific gallery – selected by id. But in the class image the method delete also checks if the deleted image was the last one in a gallery – if so this gallery should be deleted by passing the id to the delete method of the class gallery.
How could this be done best? – Or is there a complete different better way of doing something like this?
Thanks for your anwers!
Composition .. the
imageinstance has an instance of the gallery that it belongs to (if it can belong to multiple galleries that complicates things).