상세 컨텐츠

본문 제목

Dependency Inversion Principle - Template Pattern

Java

by techbard 2016. 7. 22. 18:15

본문

반응형



#


High-level code says to low-level code:


"Don't call us, we'll call you."


#


Frameworks are, in fact, a natural extension of THE TEMPLATE PATTERN.


BTW, The template pattern does not have anything to do with generic classes or templated containers.


In the template pattern, a complicated algorithm is implemented.

(Usually in the form of an instantiated method of an abstract base class.)


The abstract base class is a "template" for the complicated operation.


The abstract (unimplemented) methods left for the programmer are called "hooks".


# Basic point of the Template Pattern


1. Specify a complex set of steps, and have client code plug in specific implementations of individual steps.


2. Allow subclasses to customize parts of an algorithm, but force them to adhere to the overall algorithm.


# Use a framework


Frameworks are complicated collections of interconnected classes.


Using a framework gives way more power, but a lot less control than coding from scratch.


In using a framework, the real challenge is understanding how different classes and events in the framework interact with each other.


Listening on events is an important part of using frameworks correctly.


Framework makes EVENT, THE LISTENER waiting for and decide how to react to the EVENT is called.


When THE EVENT actually occurs, the Framework will call THE LISTENER code and pass it an object with the details of what just happened.


반응형

관련글 더보기

댓글 영역