In university, we are taught that a composition is quite important to keep your code clean and efficient. For example, a playtile class object could only exist in a playfield class object. If there is no playfield, there could not be a playtile. However, we were never taught how to implement such a thing. When I asked, I got an answer similar to "Add a check in the constructor." or something along those lines but I have no clue on how I would implement that (I don't know what to look for or what the official terms are). One of my attempts was inheritance. The teachers did not like that, let's keep it at that...
So, how does a composition work in practice? How could I make it so the playfield class is the only class that could instantiate a playtile without inheritance?
In practice a class that references another doesn't impose constraints on the class it references. Its not desirable for a class to care about what is referencing it. For example: you would not want to enforce this constraint when you write unit tests. I would never make it so the playfield class is the only class that could instantiate a playtile.
For a concrete example of how composition is implemented in the wild, check out the Unity3d game engine: https://www.youtube.com/watch?v=8TIkManpEu4