Skip to main content

Posts

Showing posts from July, 2021

Identify the type of array

 Interview question: An array is given and it can be of four types: (a). increasing (b). decreasing (c). first increasing then decreasing (d). first decreasing then increasing Without traversing the array we need to tell its type.There was a long discussion on this question.

Template Method Pattern

Definition : define the skeleton of an algorithm in a a method, deferring some steps to subclasses. Template Method pattern lets subclasses redefine certain steps of an algorithms without changing the algorithm's structure.  Class diagram: The OO Principles:  - The Hollywood Principles:   Dont call us, we'll call you. The template method in supper class tell the subclasses that, dont call us, we'll call you. The supper class is on high level component, it has control over the algorithm, and call the subclasses only when they're need for an implementation of template method.  The client will depend on the abstraction supper class rather than the concrete subclasses, which reduce the dependencies of overall system. Advantages: - There is no code duplication. (the reusable code is pulled to the parent class) -   Flexibility lets subclasses decide how to implement steps in an algorithm. Disadvantages: - Difficult for debug and  maintenance. Relation with other ...