Currently I have a car class that has a lot of methods on it, most involved with generating parts of the car (door, wheels, cars,etc), and then returns the new car class with the new parts. I'd like to be able to call the class methods, and then log the methods and arguments used, and be able to do a "replay" of generating that car.
The only way I can think of is to insert some code in every method that records what just happened, push this log in an array, and then have a separate bloated method that is a bunch of switch statements that'll call upon the relevant method used. However that seems pretty inefficient and will have to be updated every time a new method is added and become too cumbersome. Is there an easier solution to tackle this?
Also am able to get the method names as strings with
Object.getOwnPropertyNames(Object.getPrototypeOf(dude)
But this still doesn't solve logging the method used, and then using the method