You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>The composite pattern is a partitioning design pattern. The composite pattern describes that a group of objects are to be treated in the same way as a single instance of an object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies.
According to the Gang of Four, MVC is nothing more than combination of:
906
+
-->
901
907
902
-
- Strategy
903
-
- Composite
904
-
- Observer
908
+
-策略模式 (Strategy)
909
+
-组合模式 (Composite)
910
+
-观察者模式 (Observer)
905
911
912
+
其中,页面 (view) 即是各部件的组合。非常相似的是,AngularJS 中的页面 (view) 就是由 directives 及其对应的 DOM 元素所形成的组合。
913
+
<!--
906
914
They state that the view is composition of components. In AngularJS the situation is similar. Our views are formed by a composition of directives and DOM elements, on which these directives could be applied.
915
+
-->
907
916
917
+
让我们来看以下例子:
918
+
<!--
908
919
Lets look at the following example:
920
+
-->
909
921
910
922
```HTML
911
923
<!doctype html>
@@ -934,13 +946,22 @@ myModule.directive('zippy', function () {
This example defines a simple directive, which is a UI component. The defined component (called "zippy") has header and content. Click on its header toggles the visibility of the content.
952
+
-->
938
953
954
+
在第一段例子中,我们注意到整个 DOM 树就是由很多元素形成的组合。其根组件是 `html` 元素,紧接着是嵌套的 `head` 和 `body` 等等。
955
+
<!--
939
956
From the first example we can note that the whole DOM tree is a composition of elements. The root component is the `html` element, directly followed by the nested elements `head` and `body` and so on...
In the second, JavaScript, example we see that the `template` property of the directive, contains markup with `ng-transclude` directive inside it. So this means that inside the directive `zippy` we have another directive called `ng-transclude`, i.e. composition of directives. Theoretically we can nest the components infinitely until we reach a leaf node.
962
+
-->
942
963
943
-
###Interpreter
964
+
#### <aname='interpreter'>解释器模式 (Interpreter)</a>
944
965
945
966
>In computer programming, the interpreter pattern is a design pattern that specifies how to evaluate sentences in a language. The basic idea is to have a class for each symbol (terminal or nonterminal) in a specialized computer language. The syntax tree of a sentence in the language is an instance of the composite pattern and is used to evaluate (interpret) the sentence.
0 commit comments