How do I reorganize this?

therefore, in my application, I have several different clients that are "served." Each client has its own implementations of various classes, all of which are based on interfaces.

When adding the last client, I noticed that there will be a lot of code duplication with another client, but the other client is not otherwise associated with them.

I already have a default implementation for several other clients and roll new ones as I need them.

My question is, how do I reorganize this and still keep the code clean? If I were a developer of a new code base, I would like each client to use either the default or their own implementation of these classes ... but this is a lot of duplication.

+3
source share
7 answers

Consider using a base class abstractwith abstractor members virtual. Abstract members are essentially equivalent to interface members (they have no built-in behavior, they only guarantee that the method exists), while members virtualhave a default implementation that can be overridden by derived classes.

Your question is really too vague to answer in full, but here is how you can use inheritance.

If you want all classes to use the same element implementation, then this member can be implemented in the base class.

, , abstract, .

, , , .


, , // . , , ; .

+5

, , - . , .

+2

( ), ( ).

+1

, ... , , :

STW , "" . , - , - - ( - abstract virtual) .

( , ) . . , "" , NullValidationStrategy, ParanoidValidationStrategy, , , . , , , , .

, Injection (DI) "" , - , SetSomeOperationStrategy(ISomeOperation StrategyToUse) , . DI, , . , , , - factory ( factory method).

+1

( ), , :

, . , -.

, . ninject "" ​​ .

" " "ClientX" , "Bind.To()".

  • , /
  • ( : . , , )

(, , , ). , , ) .

, (, , ).

0

, @the_joric, , , - , , . , , , , , . , - , , - , , .

0

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


All Articles