IOS development-Mobile Platform Architecture Design

Source: Internet
Author: User
Tags date1

Low-coupling enterprise-level System Architecture Design

We often call javaee or. NET products as "systems", while mobile platforms (mainly Android, IOS, and window phone) develop products as "Applications ". "System" is complicated and requires architecture design, while "application" is relatively simple. Does this mean that we do not need to consider architecture issues?

 

First, let's take a look at the enterprise-level system architecture design. The principle of software design is to improve the "reusability" and "scalability" of software systems. The system architecture design adopts the hierarchical division method, and these layers are loosely coupled, the layers are highly cohesive. Reducing coupling is the goal of software design. Being able to design low coupling systems means that our systems are "Reusable" and "scalable ". General low-coupling javaee and. net enterprise-level system architecture diagram.

The presentation layer is a set of components for user interaction with the system. Users submit requests or send instructions to the system through this layer. The system then receives user requests or instructions through this layer, after the command is digested and absorbed, the next layer is called, and the call result is displayed to this layer. The presentation layer should be lightweight and should not have business logic.

The business layer is the core business processing layer of the system. It is responsible for receiving instructions and data from the presentation layer. After digestion and absorption, it processes the organizational business logic and returns the results to the presentation layer.

The data persistence layer is used by the service layer to access the database layer. In terms of design specifications, to reduce coupling, the service layer should not have code to access the database, the database access code should be placed in the data persistence layer.

The information system layer is the data source of the system. It can be databases, files, legacy systems, and network data.

Layered Architecture Design of Mobile Platforms

The application of the mobile platform is a scaled-out system, which also requires architecture design. However, not all applications must be based on the general low-coupling enterprise-level system architecture, this architecture design mode is generally used for information processing applications. For example, some games have their own game engines, and the engine is also an architectural design. The hierarchical architecture design of General Information Processing Applications on iOS platform.

Presentation layer: the presentation layer in IOS is composed of the uikit framework, which includes the views, controllers, controls, and event processing that we learned earlier;

In the business logic layer, the framework used depends on the specific business, but it is generally an objective-C and C ++ encapsulated class with certain business processing functions, or C-encapsulated functions.

The data persistence layer provides local or network data access. It may be an API function for accessing SQLite data, coredata technology, nsfilemanager for accessing files, or network communication technology, the method depends on what the information system layer is.

Information system layer. for iOS, its information sources are local and network. Local data can be stored in files or databases. Currently, the local IOS database uses sqlite3. The network can be a certain cloud service or a general web service.

Layer Based on the same project

Architecture is of practical significance for the development of our iPhone and iPad. If we want to write an IOS (iPhone and iPad)-based "My memorandum" app, it has the basic functions of adding, deleting, and querying memos, and the "Memorandum" app use case diagram, after the hierarchical design, the presentation layer can have different iPhone and iPad versions, and the business logic layer, data persistence layer, and information system layer can all be shared. This can greatly reduce our workload, which is the benefit of hierarchical design.

Considering the iPhone and iPad platforms for iOS, we have drawn a prototype sketch and a prototype sketch of the iPhone "My memorandum" application design. The "my memo" horizontal screen design prototype sketch of the iPad version and the "my memo" vertical screen design prototype sketch of the iPad version.

 

 

On the iOS platform, there are multiple methods of layering: layering based on the same project, layering based on different projects in a workspace, and static Link Library layering. This section describes the layers based on the same project.

We have already introduced how to build an adaptive iPhone and iPad project in the previous article, that is, the layered model based on the same project that we will talk about now. Read the code of the "Memorandum" application, and do not introduce the implementation process. Open the "mynotes" project and there are three groups in the xcode project navigation panel: presentationlayer, businesslogiclayer, and persistencelayer. The purpose of creating these three groups is to put classes in different layers into the corresponding group for convenience of management. presentationlayer is the class associated with the placed presentation layer, and businesslogiclayer is the class associated with the placed business logic layer, persistencelayer is a class related to persistent layer placement.

How can we divide the layers below? We can divide data by business module or component function. In this application, the persistencelayer layer is also divided into two groups: Dao and domain. Dao places data access objects. This object contains four types of crud methods for data access, to reduce coupling, Dao is generally designed as a protocol (or a Java Interface), and different implementations are adopted based on different data sources. Domain groups are Entity classes, and entities are people, things, and things in applications.

The code for notedao. h In the DaO group is as follows:

@ Interface notedao: nsobject // Save the data list @ property (nonatomic, strong) nsmutablearray * listdata; + (notedao *) sharedmanager; // Insert NOTE method-(INT) create :( note *) model; // Delete the Note method-(INT) Remove :( note *) model; // modify the note method-(INT) Modify :( note *) model; // query all data methods-(nsmutablearray *) findall; // query data by primary key method-(note *) findbyid :( note *) model; @ end

 

 

The listdata attribute is used to save data in a data table. Each element is a note object, and a note object represents a piece of data in the data table. + (Notedao *) The sharedmanager method is used to obtain the notedao singleton object. The notedao. m code in the DaO group is as follows:

@ Implementation notedaostatic notedao * sharedmanager = nil; + (notedao *) sharedmanager {static exactly once; dispatch_once (& once, ^ {nsdateformatter * dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat: @ "yyyy-mm-dd hh: mm: SS"]; nsdate * date1 = [dateformatter datefromstring: @ "2010-08-04 16:01:03"]; note * note1 = [[Note alloc] init]; note1.date = date1; note1.content = @ "welcome To mynote. "; nsdate * date2 = [dateformatter datefromstring: @" 16:01:03 "]; note * note2 = [[Note alloc] init]; note2.date = date2; note2.content = @ "Welcome to mynote. "; Sharedmanager = [[self alloc] init]; sharedmanager. listdata = [[nsmutablearray alloc] init]; [sharedmanager. listdata addobject: note1]; [sharedmanager. listdata addobject: note2];}); Return sharedmanager;} // Insert NOTE method-(INT) Create :( note *) model {[self. listdata addobject: Model]; return 0;} // Delete the Note method-(INT) Remove :( note *) model {for (note * Note in self. listdata) {// compare whether the date primary key is equal if ([Note. date is1_todate: model. DATE]) {[self. listdata removeobject: Note]; break;} return 0;} // modify the note method-(INT) Modify :( note *) model {for (note * Note in self. listdata) {// compare whether the date primary key is equal if ([Note. date is1_todate: model. DATE]) {Note. content = model. content; break;} return 0;} // query all data methods-(nsmutablearray *) findall {return self. listdata;} // Method for querying data by primary key-(note *) findbyid :( note *) model {for (note * Note in self. listdata) {// compare whether the date primary key is equal if ([Note. date is1_todate: model. DATE]) {return note ;}} return nil ;}@ end

 

The implementation of notedao adopts the singleton design mode. This design has nothing to do with the DAO design mode, mainly for the convenience of data access. Data is stored in the listdata attribute (this should be from the database, but we haven't learned about the database access technology). The crud method also processes listdata, not the database.

The note code in the domain group is as follows. There are only two attributes date: the date on which the memo is created, and content is the memo content:

//// Note. h # import <Foundation/Foundation. h> @ interface Note: nsobject @ property (nonatomic, strong) nsdate * date; @ property (nonatomic, strong) nsstring * content; @ end // note. M # import "note. h "@ implementation note @ end the class design in the businesslogiclayer of the business logic layer is generally designed according to the business module. Its method is the business processing method. The following code is notebl. H code: @ interface notebl: nsobject // Insert NOTE method-(nsmutablearray *) createnote :( note *) model; // Delete Note method-(nsmutablearray *) Remove :( note *) model; // query all data methods-(nsmutablearray *) findall; @ end

 

Three methods are defined in notebl. h. The three methods are defined based on my business needs. For business requirements, refer to the use case diagram. The following code is notebl. M:

@ Implementation notebl // Insert NOTE method-(nsmutablearray *) createnote :( note *) model {notedao * Dao = [notedao sharedmanager]; [Dao create: Model]; return [Dao findall];} // Method for deleting the note-(nsmutablearray *) Remove :( note *) model {notedao * Dao = [notedao sharedmanager]; [Dao remove: Model]; return [Dao findall];} // query all data methods-(nsmutablearray *) findall {notedao * Dao = [notedao sharedmanager]; return [Dao findall];} @ end

 

 

The content is sourced from ios6 Development Guide by Guan Dongsheng.

Related Article

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.