The eighth chapter is the behavior-centered programming

Source: Internet
Author: User

The eighth chapter describes behavior-centric programming this chapter introduces the function representation behavior Extender behavior handler function and closure with decision tree test client in chapter seventh, we discussed the application in the data center, knowing that the first step in designing a functional program is to define the relevant data structure. In another case, the data structure contains some form of behavior, either a user-invoked command or a task that the program performs at a certain point. In this case, we want to unify the processing, rather than hard-coding the functionality of each behavior, so that the design of the data structure needs to be easily modified, both at compile time and at runtime. The behavior-centric application example we discussed in chapter seventh is working with graphics filters to manipulate images. The application needs to save the filter to add or remove filters as needed by the app. When a filter is represented in a program, we can use a list to represent the collection of filters that are actually applied, and the more difficult question is what data structures should we use to represent the filter itself. Obviously, a filter is not real data, although it may be parameterized in some way, instead it represents behavior, and the simplest way to represent behavior in a functional language is to use a function. In the fifth chapter, we already know that a function can be considered a value, so you can treat the function just like any other data type. Thus, using a list of functions to represent a graphical filter is a perfectly reasonable data structure. The distinction between behavior-centric and data-centric is more conceptual than technical. It is helpful to understand which type of application is being designed and to create the appropriate design. If your application meets any of the following criteria, you might want to design a behavior-centric application that is not (impossible) to know the exact set of required features beforehand. The user or programmer should be able to easily add new behaviors. The program can be extended using an external plug-in. Users can create tasks by combining simple functions. From the previous chapters we know that the function of data-centric programming is largely dependent on functional data types, the most important of which is the differential union. In C #, this is not particularly customary, so we're mainly talking about F #. On the other hand, in C # 3.0, it is entirely possible to use functions to represent simple behavior. Because functions can be represented in C # with the Func delegate, most of the examples in this chapter can be written in C # and F #. Note In a fairly large application, it is common to combine two methods. The large graphics editor supports both vector graphics filters and raster graphics filters, and may use a data-centric approach to representing shapes, a behavior-centric approach, and applying graphic filters to images. Implementing the content at the drawing is beyond the scope of this chapter, but you can find the graphical processing sample application in Http://www.functional-programming.net. In this chapter, we will use a non-An example of a broken extension that demonstrates a behavior-oriented application; We will develop an application to check whether a loan should be provided to the customer.

Eighth behavior-centric programming

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.