ThinkPHP3.0 Understanding _php Tutorials

Source: Internet
Author: User
See the new version of ThinkPHP3.0, very excited because it presents a lot of new concepts such as CBD mode, AOP programming ideas. Focus on these two new concepts to make a summary.

CBD knowledge

Citing the Official Handbook: the ThinkPHP3.0 version introduces the new CBD (core core+ behavior behavior+ driven driver) architecture pattern, since the framework uses core + behavior + driven architecture from the ground up, and the core retains the most critical part, And in the important position of the label to mark, and other functions are the behavior extension and the combination of driving, the developer can according to their own needs, a label location to expand or replace the behavior can be convenient to customize the framework of the bottom, you can also add their own label location and add application lines at the application layer. and the label location is similar to the AOP concept of "tangent", the behavior is around this "aspect" to program, if the system built-in core extension as a standard mode, then the user can put all this behavior custom packaged into a new pattern, so in thinkphp, called the pattern extension, In fact, pattern extensions can not only replace and increase behavior, but also replace and modify the underlying MVC to achieve tailored purposes. With this new feature, developers can easily customize a set of their own or enterprise development framework through the expansion of the schema, the version of the model extension is the framework of the expansion of the synthesizer, creating a milestone, which is the real charm of the latest version.

AOP Awareness

Refer to the Official Handbook:

AOP (aspect-oriented programming, aspect-oriented programming) can be said to complement and improve OOP (object-oriented programing, object-oriented programming). OOP introduces concepts such as encapsulation, inheritance, and polymorphism to create an object hierarchy that simulates a collection of public behavior. When we need to introduce public behavior to scattered objects, oop seems powerless. In other words, OOP allows you to define relationships from top to bottom, but it is not appropriate to define left-to-right relationships. such as logging capabilities. Log code is often spread horizontally across all object hierarchies, and has nothing to do with the core functionality of the objects it spreads to. This is true for other types of code, such as security, exception handling, and transparent persistence. This irrelevant code scattered around is called crosscutting (cross-cutting) code, and in OOP design, it leads to a lot of duplication of code, rather than the reuse of individual modules. AOP, on the contrary, uses a technique called "crosscutting" that splits the encapsulated object interior and encapsulates public behavior that affects multiple classes into a reusable module, called "Aspect", which is the facet. The so-called "aspect", in a nutshell, is to encapsulate the logic or responsibility that is not related to the business, but for the common invocation of the business module, to reduce the duplication of code in the system, to reduce the coupling between modules, and to facilitate future operability and maintainability. AOP represents a horizontal relationship, if the "object" is a hollow cylinder, which encapsulates the properties and behavior of the object, then the aspect-oriented programming approach is like a razor that cuts through the hollow cylinders to get inside the message. The cut-off aspect is the so-called "facet". Then it hands the cut-off slices with a clever capture of the heavens, leaving no traces.

Using "crosscutting" techniques, AOP divides software systems into two parts: core concerns and crosscutting concerns. The main process of business process is the core concern, and the part that has little relation is the crosscutting concern. One feature of crosscutting concerns is that they often occur in many of the core concerns and are essentially similar everywhere. such as permission authentication, logging, transaction processing. The role of AOP is to separate the various concerns in the system, separating the core concerns from the crosscutting concerns. As Avanade's senior program architect Adam Magee says, the core idea of AOP is "separating the business logic in the application from the generic services that support it." ”



Personal knowledge: AOP is a programming idea, which is to make a section of the entire project's functional modules that need to be reused, so that we do not write code repeatedly in this project. And the CBD is the realization of the idea of AOP, some need to use more functions (so-called cut-off) to write a behavior, so that we just use this behavior is good, this behavior there is only one way to call that is run, The behavior of other behavior classes is the private property. And, this invocation is encapsulated as B ($name, & $param) This method, when we invoke the tangent behavior, as long as the B method is done. (This form, in line with the idea of dependency injection, is the benefit of implementing code decoupling).

So, if you use thinkphp2.x how to do not change the framework of the premise, you can better use these good programming ideas. At present, the first thing to do is to plan the project, for example, for some recurring behavior, such as the data for the project-level special validation, you can make it a plane (Behavior), so we just repeat the use of this aspect.

Probably read ThinkPHP3.0, personally think, 3.0 and 2.X not much difference, but 3.0 more emphasis on our current planning, using the AOP idea to avoid duplication of code. Take the nutrients from them and use them in your usual programming.

http://www.bkjia.com/PHPjc/478315.html www.bkjia.com true http://www.bkjia.com/PHPjc/478315.html techarticle See the new version of ThinkPHP3.0, very excited because it presents a lot of new concepts such as CBD mode, AOP programming ideas. Focus on these two new concepts to make a summary. CBD recognition quote Official hand ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.