I'm working on a legacy warehouse system. There is one Aggregate root,
Product which has its correspondent
Right now I have a new requirement that says the following:
Some Products are Purchasable and need to keep track of the datetime they have become purchasable.
So, in order to implement this requirement, I decided to take the following approach that, since I can see a "is-a" relationship, I decided to create a new class called
PurchasableProduct which inherits
Product and adds this new attribute.
class PurchasableProduct(Product): def __init__(product_properties, purchasable_datetime): super().__init__(product_properties) self.purchasable_datetime = purchasable_datetime
What's bugging me right now are the repositories.
ProductRepository, of course, should still return instances of
Products (even though they might be
PurchasableProducts), but I need a way to retrieve and save those PurchasableProducts. Adding a
PurchasableProductsRepository seems a solution but it's kind of weird that I can have two repositories,
PurchasableRepository, that I can use to save instances of
In a DDD paradigm, what would be the best way to implement this situation where an aggregate root is an specialization of another one?