在我的项目中,我必须维护类的版本。所以我可以采用两种方法
1) Edit Same Class with Version and Use Switch Case for maintain older version
Pro :
1) We only have to create one single class
2) If you want to used old version class attribute which are now not supported in
current version of class so you just provide them Default Values.
Cons:
1) There may be possibility that some attribute are not used now but they still
present in Class for supporting older version
2) It also break Open Closed Principle
下一个方法:
2) Create new classes for each version and maintain them by using any design pattern
so for example I have Base Class = BaseClass and It have multiple Derived classes
like DerivedClass1,DerevivedClass2. Each class have different version.
Pro:
1) If now we want to use old version class so we not have to worry about its
attribute behavior because we will fetch DerivedClass1 for Version 1 ,
DerivedClass2 for Version 2
2) We will put all common property in Base class so Derived class will only have
extended property.
3) We also follow Open Closed Principle
Cons:
1) We need to create new classes for all new versions.
因此,我想知道您对此的看法,如果您需要更多说明,请告诉我。