News for hackers. Stuff that matters.
Re:A Healthy Hatred of OOP, or the principles of my message-... by spriggan3 on Wednesday April 13, 2016 @05:07AM (#11486775)
> An example of where this can all go wrong is if you have a TCP object that opens a connection to a remote server and then lets you read and write the socket. Someone decides that they need to find out what IP address the object used when it connected and create a get_ipaddr() method that returns a s_addr type. But then the TCP object is updated to support IPv6 and now the author needs to figure out how to return a V6 IP address to external methods that only expect V4

In that case you should use polymorphism. There is no reason why the consumer of the address returning the IP should know whether get_ipaddr returns an IPV4 or an IPV6 directly.

There are no comments on this comment yet.