Suppose there are two signs on the map, a hospital and a road, and these two signs have their own attribute data:
For example, a hospital has attributes such as grade, number of buildings, number of patients, floor area, name, etc. ;Roads have attributes such as name, grade, length, construction time, etc. That is, different types of map identifiers have different attribute data, and it is also necessary to consider that new attributes will be added in the future.
I would like to ask everyone, can you give me a rough design idea (just the design idea of static class diagram)?
PS: My own idea is to implement it through the decorator pattern, but in that case, every time an attribute is added in future extensions, the original class will have to be decorated again, or the originally designed class will be directly invaded. , add attributes.
PHPz2017-05-27 17:43:12
haha, why not use Dictionary type, for example, use map to store key-value pairs?
迷茫2017-05-27 17:43:12
It should comply with the opening and closing principle. It is best not to modify an entity class after it is created. Just use inheritance to add new attributes to the original attributes without destroying the original structure