I have 3 different objects, lets call them: Box, Square, Triangle. Now, I want to make an update function that requires an object to be passed. As far as I know, the function would look like this
void Update(Box box, Square square, Triangle triangle)
{
//do something
}
That would require me to pass all three object even if sometimes I want to update just one of them. The other way I know would be by initializing objects previously in constructor and pass them into a private variable that is inside the class. Then I would update all of the objects, whether I want to update all of them or not.
void Update()
{
//do something for Box
//do the same for Square
//do the same for Triangle
}
This would require a lot of code, sometimes unnecessary. Now, is there any way that I could pass whichever object do I want and do the same code. For example
void Update(Object randomObject)
{
//do something for the randomObject whether its Square, Box or Triangle
}