Let's understand the method handing and overriding practically. It is considered as runtime polymorphism or dynamic polymorphism or late binding. It is considered as compile-time polymorphism or static polymorphism or early binding. Method resolution takes care by JVM based on runtime object. Instead of your class inheriting behavior from a super class, you define the behavior in a separate class and your class has-a. The purpose of the Strategy pattern is to promote the use of composition (has-a) over inheritance (is-a). Method resolution takes care by the compiler based on the reference type. Similarly, the Strategy pattern relies on polymorphism but that does not mean that they are the same thing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |