Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C language to realize POOO pattern

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use C language to achieve POOO pattern related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this article on how to use C language to achieve POOO pattern will have a harvest, let's take a look.

MyNotes project, as shown in figure 2. In the Xcode project navigation panel, there are 3 groups.

The code section is described below. In the dao group, the code for NoteDAO.h is as follows:

@ interface NoteDAO: NSObject

/ / Save data list

@ property (nonatomic,strong) NSMutableArray* listData

+ (NoteDAO*) sharedManager

/ / method of inserting memos

-(int) create: (Note*) model

/ / method of deleting memo

-(int) remove: (Note*) model

/ / the method of amending the memorandum

-(int) modify: (Note*) model

/ / method of querying all data

-(NSMutableArray*) findAll

/ / the method of querying data by primary key

-(Note*) findById: (Note*) model

@ end

In the above code, the listData attribute is used to hold the data in the data table, where each element is a Note object. The + (NoteDAO*) sharedManager method is used to obtain the NoteDAO singleton object. In the dao group, the code for NoteDAO.m is as follows:

NoteDAO also uses singleton design pattern to implement.

In the domain group, the code for Note is as follows, which has only two properties-- date is the date the memo was created, and content is the content of the memo:

/ /

/ / Note.h

/ /

# import

@ interface Note: NSObject

@ property (nonatomic, strong) NSDate* date

@ property (nonatomic, strong) NSString* content

@ end

/ /

/ / Note.m

/ /

# import "Note.h"

@ implementation Note

@ end

In the business logic layer BusinessLogicLayer, the code for NoteBL.h is as follows:

@ interface NoteBL: NSObject

/ / method of inserting memos

-(NSMutableArray*) createNote: (Note*) model

/ / method of deleting memo

-(NSMutableArray*) remove: (Note*) model

/ / method of querying all data

-(NSMutableArray*) findAll

@ end

Here is the code in NoteBL.m:

@ implementation NoteBL

/ / method of inserting memos

-(NSMutableArray*) createNote: (Note*) model

{

NoteDAO * dao = [NoteDAO sharedManager]

[dao create:model]

Return [dao findAll]

}

/ / method of deleting memo

-(NSMutableArray*) remove: (Note*) model

{

NoteDAO * dao = [NoteDAO sharedManager]

[dao remove:model]

Return [dao findAll]

}

/ / method of querying all data

-(NSMutableArray*) findAll

{

NoteDAO * dao = [NoteDAO sharedManager]

Return [dao findAll]

}

This is the end of the article on "how to implement POOO pattern in C language". Thank you for reading! I believe that everyone has a certain understanding of "how to use C language to achieve POOO mode" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report