官术网_书友最值得收藏!

Getting to know Angular components

Model-View-Controller (MVC) is a micro-architectural pattern initially introduced for the implementation of user interfaces. As Angular developers, we use different variations of this pattern on a daily basis, most often, Model-View-ViewModel (MVVM). In MVC, we have the model, which encapsulates the business logic of our application, and the view, which is responsible for rendering the user interface, accepting user input, and delegating the user interaction logic to the controller. The view is represented as composition of components, which is formally known as the composite design pattern.

Let's take a look at the following structural diagram, which shows the composite design pattern:

Figure 5

Here, we have three classes:

  • An abstract class called Component.
  • Two concrete classes called Leaf and Composite. The Leaf class is a simple terminal component in the component tree that we will build soon.

The Component class defines an abstract operation called operation. Both Leaf and Composite inherit from the Component class, however, the Composite class also owns references to it. We can take this even further and allow Composite to own a list of references to instances of Component, as shown in the diagram. The components list inside Composite can hold references to different Composite or Leaf instances, or instances of other classes, which extend the Component class or any of its successors. We can have a different behavior of the operation methods of the individual Component instances invoked within the implementation of the operation method of Composite. This is because of the late-binding mechanism used for the implementation of polymorphism in object-oriented programming languages.

主站蜘蛛池模板: 岳西县| 青阳县| 绵阳市| 红河县| 临高县| 乌鲁木齐市| 庆安县| 包头市| 丽江市| 玛曲县| 波密县| 华宁县| 青浦区| 乐业县| 汉中市| 巩留县| 孙吴县| 利津县| 青铜峡市| 延寿县| 济南市| 柞水县| 洛隆县| 洪泽县| 柳江县| 鄂尔多斯市| 常宁市| 罗平县| 宁南县| 婺源县| 达州市| 新野县| 绥阳县| 沧州市| 玉林市| 桑日县| 巨野县| 沂水县| 罗甸县| 利川市| 巴彦淖尔市|