Given that I have 3 classes Asset
, AssetA
, AssetB
what is the proper way to structure inheritance when using the factory method?
Here is how I would like to use these classes:
Asset.new(data)
should deterministically create eitherAssetA
orAssetB
depending on some flag present indata
Asset
should also act as a super class in a sense that it's methods should also be present inAssetA
andAssetB
I would create a base Asset class and have AssetA and AssetB inherit from it. The factory class should be a separate class - AssetFactory - with just one single responsibility - it should create new Asset object based on some conditions.