The visual FoxPro in my eyes 8.0 (i)

Source: Internet
Author: User
Tags exception handling final

Acknowledgement

Friends who often come to the BOE know that I have long been an amateur foxer, and as time goes on, every writing is uneasy, really worried about making some misleading remarks or laughable.

Every time I finish the first draft I will give a preview to some friends and listen to their suggestions. The Boby, the future is my three netizens are my first readers, thank them again and again read those obscure words, understanding immature thought. The Rambler, in particular, became my personal secretary, and for this article, all the little headings in the body were added to him. It makes it easier for readers to read ...

After the written, belong to my name, is really white occupation of others suspected of labor, here to these friends express deep thanks!

Write in the beginning

That day, I wait for Visual FoxPro 8 download, until 2 o'clock in the morning, it is really not endure, this just sleep; 4 o ' clock, was awakened by the alarm, sleepy eyes saw the visual FoxPro 8 download connection, stumbled also know how the action is done, anyway, wake up in the morning Visual FoxPro 8 is already on my hard drive. Decompression, installation, a burst of excitement is difficult to say, suddenly think of, but also to work, so burn plate, walk ... In this way, I started my Visual FoxPro8 to explore the journey.

Originally thought, has seen a large number of original material (thank evening primrose, RMH, Fbilo they have translated these things, English bad friends can now enjoy), I study visual FoxPro only need a small amount of energy. Hey, who knows: I actually spent a whole 10 days to see what I am interested in. And it was a day of fighting until the wee hours, and the family had a lot of advice, but how did they know I enjoyed it?

In October this year, Microsoft released the Visual FoxPro 8b version, this is since the visual FoxPro 3 another wonderful version, all of a sudden attracted the global foxers eyeball! Below is my study, explore the Visual FoxPro 8b Some feelings, is willing to share with the reader.

(i) structured exception handling

People often ask me where you think Visual FoxPro needs improvement. I always answer without hesitation: Exception handling! It is expected that it can have structured exception handling mechanism, limit the exception and its processing to the smallest range, so that the encapsulation of the code better.

Visual FoxPro 8 has previously limited exception handling to global on Error routines and object error events, and they all have the problem that once an exception occurs, the program must jump out of the executing program module and execute the exception handling routine. The context of the program module executed before the exception is lost, the system is difficult to adjust to the normal state or give the calling interface a clear answer!

Visual FoxPro 8 's Try ... Catch... Finally ... The end Try structure is exciting, it helps us to easily grasp the "exception", immediate response to a variety of anomalies, reduce the scope of the impact of the exception to protect the operating state of the system, but also make the packaging of the program module better. Think of the previous deal with "abnormal" and the design of a variety of programs, overnight became a former yellow, looks so pale, really "sea change Kuwata" Ah!

With only this enhancement, visual FoxPro 8 is already dazzling, believing that no developer will be tempted to "structured exception handling" to upgrade to Visual FoxPro 8!

(ii) CursorAdapter class

The CursorAdapter class provided by Visual FoxPro 8 is also a popular delight. CursorAdapter is an object-oriented Cursor processing model based on loosely coupled thought design.

1, VFP8 before the data processing

Before visual FoxPro 8, I evaluated the data processing in the visual FoxPro: flexible and robust, oriented to record processing, oriented to set processing, using a procedural programming model, but the object-oriented XBase language could be used to encapsulate data processing objects.

When it comes to the flexibility and robustness of visual FoxPro processing data, the final word is that visual FoxPro supports both Xbase and SQL languages. XBase language is good at sorting records, this kind of processing is often based on "line" mode, the SQL statement of data processing is based on the concept of "set", according to the conditions of the "collection", and then processed. Whether you are working with data in the XBase language or using the SQL language, Visual FoxPro defaults to providing a process-oriented data-processing programming model, rather than a popular object-oriented programming model. (Of course, Visual FoxPro does not restrict developers from writing their own data-processing objects.) )

So what is the so-called "data" in Visual FoxPro? It's cursor!. In visual FoxPro the entire data processing is around the Cursor (rather than DBF), so the object-oriented data processing model should also start from the Cursor!

2. Object-oriented Data processor

In visual FoxPro Design object of Cursor is not much significance, this sentence is abrupt, let a person touch mind!

We analyze the RecordSet of a typical object-oriented cursor ――ado component. You can find that the recordset defines the source of the data set, the structure of the data set (table structure), the update loopback of the data, and the recordset can manipulate the data collection, such as Move, find, delete, and so on.

In Visual FoxPro object Cursor, is not to copy the set of the RecordSet? If we were to design this framework, how would we choose? I think there is no need to realize the encapsulation of Cursor itself, this is in self-inflicted wounds, I have already said: The entire Visual FoxPro of the data processing is the processing of the Cursor, if the package of Cursor, the whole system is a departure from the framework of ideas, but also gave up the Visual FoxPro is characterized by "flexibility and robustness" in data processing. This is the previous reference to "Cursor in Visual FoxPro design is not of great significance."

The object of Cursor is meaningless, so what do we need?

An object-oriented Cursor processing (management) device is used to manage Cursor data source, Cursor data structure, and update loopback of data changes in Cursor; Cursor is still the traditional Cursor, without any change, can still use XBase or The SQL language deals with direct Cursor-this is what we need.

Speaking of which, people will ask, is this not the view in DBC? They do look a bit like the functionality they implement, but there's a difference in substance:

First of all, the view is DBC object (component), the system that uses view design is dependent on the DBC, does not conform to the idea of multi-layer system frame. Our object-oriented Cursor (processing) Manager is not related to DBC, it is entirely a concept at the programming level. From the viewpoint of multi-layer system design, it belongs to the business logic level.

Furthermore, the view is the concept in the database, poor flexibility, poor control, and the object-oriented Cursor (processing) Manager is not the same, as an object, with object-oriented program design of all the benefits, it is easy to define, change, maintain, more able to inherit use, this is not done using the view.

You can cite a few examples of weak views, sometimes the structure of the data set is consistent, but the data source is different, you have to design several views of the problem, while using the object-oriented Cursor (processing) Manager only need to change the data source properties; For example, the data source is the same, the data collection structure is the same, Just to get the data in different conditions (the Where clause is constructed differently), you have to design a new view with the view, and the object Cursor (processing) Manager only needs to change the related attributes ...

In the final analysis: The view is the concept of the database, with the characteristics of the database objects (components), but not the characteristics of the programming language, the object of Cursor (processing) Manager to solve this problem.

3. Loose coupling

In the view era or the Recordset era is a tightly coupled thinking, the straightforward point is: the data from where to update to where, the programmer can not do what interference, once the implementation of the TableUpdate (), automatically update the data source, there is no room for negotiation!

Loose coupling provides an open model that is centered on Cursor and essentially recognizes that the interrelationship between Cursor and data sources is: Data acquisition and update writeback. Data acquisition is Sql-select operation, data Update write back is Sql-insert, Sql-update, Sql-delete. The loosely coupled model provides a select child object for a Cursor data source, an Insert child object that Cursor data to add a writeback data source, an Update child object that Cursor data modifies a writeback data source, and a delete child object that Cursor data to delete a write-back data source. Because the structure of the cursor and data source of various interactive operations, and then supplemented by the event model, which gives developers a lot of programming room!

In contrast, the view uses similar ideas to interact with the data source, but it treats the entire interaction process as a whole, tightly packed, resulting in poor developer involvement.

4, the CursorAdapter object of VFP8

Let's look back at the CursorAdapter object provided by Visual FoxPro 8, which supports four sources of data by default: Native (Local data), ADO, ODBC, XML. Think about why CursorAdapter can support a number of different types of data sources, because the use of a loose coupling model, so that developers use their own code to participate in the acquisition of data, so that the expansion of the entire system greatly enhanced, which is the charm of loose coupling!

Summarizing the CursorAdapter in VFP8, it is an object-oriented Cursor processing model based on loosely coupled thought design. CursorAdapter not only retains the traditional advantages of Visual FoxPro to Cursor processing, but also introduces the advanced programming model and architecture. Emphasize its features again:

    • Cursor itself has not been targeted, is still the traditional sense of Cursor, can use all traditional statements to deal with Cursor.

    • The Cursor management method is object-oriented, the programmable is better, is advantageous to the code encapsulation.

    • Adopting the loosely coupled design thinking, taking the Cursor as the center, but dividing the various operations between the Cursor and the data source, and then adding the event model, provides a lot of opportunities for the developers to participate.

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.