Introduction to the application of design patterns in GIS

Source: Internet
Author: User
Tags driver manager map class
Application of design patterns in GIS I. Overview of design patterns

With the wide application of object-oriented technology, software reuse has been adopted in more and more development projects. In the process of studying software reuse, the concept of design pattern was proposed. The so-called design pattern is a summary of some experiences in Designing object-oriented software. Its appearance can be said to be an important milestone in the development of object-oriented theory. Geographic Information System (GIS) is a specific and important spatial information system, it is a spatial information system that collects, stores, manages, processes, analyzes, and describes data related to spatial and geographical distribution on the whole or part of the Earth's surface (including the atmosphere. It not only processes general and rule attribute data, but also massive and complex spatial data. It is usually a complicated and huge system, which is time-consuming and financial-consuming to develop. Therefore, re-implementation or re-Modification of GIS is a huge project. The idea of importing Design Patterns in the software development of geographic information systems will improve the quality of geographic information systems while improving the reusability, scalability and portability of systems, to reduce costs and share development experience. 23 design patterns are proposed in the design pattern-the basis for reusable object-oriented software.

 

Ii. necessity of applying Design Patterns in GIS

 

In the development of geographic information systems, for the purpose of reusing the basic components for development, we usually encapsulate them into class libraries using object-oriented methods and then call the client program. However, with the increasing complexity and scale-up of GIS software development, how to achieve code reuse, class reuse, and Component reuse is a severe test. To some extent, the design pattern can solve such problems as class library reuse, low coupling, and high cohesion of GIS.

 

 

Iii. Application of common design patterns in GIS

1. Factory method mode

Defines an interface used to create objects, so that the subclass determines which class to instantiate. Factory method delays the instantiation of a class to its subclass. Also known as virtual constructor ).

In GIS ry models, a base class of geometric abstraction is usually required to derive many specific entity classes, such as point and polyline. When creating a geometry object, we can use the pointer of the base class to actually point to the subclass. However, as the number of classes increases, it is inconvenient to manage them. In this case, we can use the Abstract Factory method to encapsulate the process of creating an object in the factory method.

 

2. Combination Mode

The combination mode is usually used to form the relationship between the entire-part tree. In GIS, geographical things are often abstracted into three basic types: point, line, and surface. A line consists of vertices and a line string connected to the beginning and end. As shown in:

 

3. Bridging Mode

The Bridge Mode separates the abstract part from the implementation part. Modifications to the two parts can be independent of each other. This operation can also be implemented in the inheritance system, that is, the template method, but when the demand changes, it will also cause a huge class level, which is not conducive to management.

A major function of GIS is map display. Coordinate conversion is usually used during Map Display. For example, the conversion between geographic coordinates and device coordinates. The devices here can include computer screens, printers, and mappers. You must zoom in, zoom out, or pan the display. If you write all these operations to the map class map, this will cause a huge bloated map class. If these operations are encapsulated in another displaymanager class, a pointer pointing to the displaymanager class is saved in map class map. The specific operation process is completed by displaymanager. Is a class chart.

 

4. template Mode

The most important feature of the template mode is that the virtual base class defines a series of interfaces. The specific implementation part is handed over to the entity class Rewriting Method. For example, in GIS, the geometric object model can use the template method. Geometry of the virtual base class can define some interfaces, such as area, length, and drawing functions. However, these functions have different implementations for different classes, and their ideas are very simple.

 

5. Command mode

Command intent: encapsulate a request as an object so that you can parameterize the customer with different requests, queue requests or record request logs, and support unrecoverable operations.

In GIS systems, you often encounter the need for redo/undo to edit geographical elements. In this case, you can issue these operation commands to the system. You can first implement a base class command to implement logical operation interfaces, and then implement real operations according to different operations. Its Class diagram is as follows.

The command mode can also be combined with the memorandum mode to complete undo operations, that is, cancel operations.

 

6. Policy Mode

Policy mode and template mode solve similar or identical problems. In GIS, there are various data types and new data sources may be added based on application requirements. The data formats of each data are inconsistent, and their native programming interfaces are also inconsistent. For example, the native programming interface of shapefile is shapelib. The well-known gdal/OGR class library uses this interface to read and write shapefile data. The C/C ++ read/write interface of Oracle Spatial is OCI/occi. There is also a variety of other data. It can be said that you are dedicated to data format conversion can put you down. If the GIS system does not take into account the requirements of multiple formats, it will be a disaster to greatly change the design of existing code when other data formats are used in the future. To support multiple data formats and provide unified interfaces for reading and writing, we can adopt a policy mode. For example, you can read the index file for file-type data, and then read and write the geometric data at the corresponding location based on the index file. In this way, the interface for external exposure only needs to access data according to the interface, without concern about how the underlying data is read and written. When a new data type needs to be added, you only need to add a corresponding new policy class. The specific class diagram is as follows:

7. Singleton Mode

The Singleton mode is the simplest design mode. It mainly records unique objects by maintaining a static member variable in a class. In GIS, many spatial data types allow many systems to read and write data for each data format, however, so many drivers can be conveniently managed by a drivermanager. In a system, if there are many driver managers, there is a shapefile driver in the driver manager, and there is also a shapefile driver in the driver manager, which will cause management confusion. Therefore, we need to limit the number of drivers to one to prevent such problems.

Iv. Postscript

Of course, this article cannot cover all aspects. It is impossible to explain how to apply 23 design patterns to GIS development. Some design patterns are not particularly clear at present. You are welcome to discuss the design pattern in GIS software design.

 

 

 

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.