Best practice for reusing model components?

I have a requirement to use the model Fundin my code. It will contain the name of the fund and the code of the fund. In the interest of reuse, I tried to get around the package containing the other models used, and found an existing model Fund. However, the problem is that in addition to the fund name and code, it also contains an amount. Amount is not directly relevant in my context. So do the following:

1) Use the existing model Fundas is, ignoring setters / recipients for the fund amount.

2) Place the interface FundDescriptionin an existing model Fundto access only the information of interest.

3) Create a base class FundDescriptionfrom which an existing model can now existFund

4) Create a completely new separate model, as they are slightly contextually different

+3
source share
1 answer

Option 1 can confuse the person who reads the code, and it may tempt someone who does not understand your code completely to use these setters / getters due to some misunderstanding. Other options make it better understand your code.

Option 2 Sorting the second place, but for me it will not make logical sense.

3 , , .

4 !: -)

5 (NEW! , :-) - FundDescriptor Fund.

, , , " " " , ", , , .

"extends" "is-a" . , . , "a Fund FundDescriptor" ? : ".. ", 5, 3.

+2

Source: https://habr.com/ru/post/1743498/


All Articles