How to use C language to realize POOO pattern
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.