Inheritance is the right approach

We have the base class TCP Server, which provides server functionality. Now we also want to ensure the safe operation of the TCP server. We discussed two approaches.

  • Pass the value to the TCP server designer, specifying whether it should act as a secure TCPServer or TCP server.

  • Create a TCPSecure class that inherits from the TCP Server class, for this you will need to override several methods of the base class.

The first approach has advantages that it will retain in one class.

The second approach looks more correct. But we do not expect more types of derivation. So is it worth introducing a new class for this?

Thanks in advance.

+3
source share
5 answers

, TCPSecure , , - , .

OO.

+7

, , , ( , 2 , N ), , . , , , . . N , N , , - , ?

+2

, , . . , - Server Secure Insecure ( , ).

: TCPSecure TCPServer, , TCPServer . , , , , , .

, - . . , , . , , -, .

+1

, . , , .

+1

, . , . , , , , , . - , , . , . .

0

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


All Articles