Let me explain it, this is my pseudo code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order{ | |
void perform(){ | |
} | |
} | |
class OrderA extends Order{ | |
} | |
@DependsOn(OrderA.class) | |
class OrderB extends Order{ | |
} | |
@DependsOn({OrderA.class,OrderB.class}) | |
class OrderC extends Order{ | |
} | |
class OrderSet{ | |
def orders = [OrderA.class, OrderB.class, OrderC.class] | |
void doSomething(){ | |
//process the @DependsOn metadata | |
} | |
} |
As you can see, the OrderSet has a collection of Order classes, but classes!! Not instances, because in the real application I will have hundred of Orders and I don't want to instantiate a new object for each one of them.
So to keep the memory load very low I handle classes, in that way I can control them, instantiate them and destroy them as much as I want.
Now, I tried to write it in Ruby, but I found out that there's no easy way to add metadata at a class level!!
The closest approach to it that I could find is instance-oriented. I would need a new instance of every Order to make it work....sad.