This page (revision-1) was last changed on 29-Nov-2024 16:16 by UnknownAuthor

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 1 added 22 lines
!!! Overview[1]
[{$pagename}] is one of the four fundamentals of [Object-oriented Programming]
[{$pagename}] means one name, many forms.
!! So how does it help us?
Let us consider the same example given in the [inheritance] example.
Let us say that you are writing a serialization component. It can either write the ouput to MemoryStream or NetworkStream or FileStream. If there is no [inheritance] you’ll end up writing this Serialization component for all the three cases. That’ll by quite some duplication. Since you have a base class Stream, you can use the base class variable to open, write data and close the stream after the serialization. Your method can take a prameter of type Base class Stream. If you call Open or Write or Close it is dispatched to the actual dervied type passed to the serialize method. The class to dispatch is not decided at compile time based on the variable type (The call has to be dispatched to the Stream class then). Instead the method to which the call is dispatched is decided based on what is the type of the instance passed to the method at runtime. The same open call is dispatched to the NetworkStream if the Stream parameter holds a NetworkStream instance or a FileStream if the Stream parameter holds a FileStream instance.
[{$pagename}] provides an opportunity tremendous amount of reuse and extensibility. How does it help in extensibility?
Assume you add an EncryptedStream tomorrow you still need not change the Serialize methods as long as your EncryptedStream class inherits from the Stream class. Thus [{$pagename}] allows your code to work with classes that you do not know at the time of writing your piece of code. This is what which provides extensibility.
What we discussed is runtime [{$pagename}]. Method overloading / operator overloading is an example of Compile time [{$pagename}] where the dispatch to the method is decided at compile time. Another classification is interface based polymorphic dispatch versus inheritance based polymorphic dispatch.
!! More Information
There might be more information for this subject on one of the following:
[{ReferringPagesPlugin before='*' after='\n' }]
----
* [#1] - [Four Tenets of OOP|https://codingarchitect.wordpress.com/2006/09/27/four-tenets-of-oop/|target='_blank'] - based on information obtained 2017-04-18