———————————————————————————————————————————
E-commerce app app
goods.h*****************************************************
#import <Foundation/Foundation.h>
Definition of structural body
typedef struct
{
int year;
int month;
int day;
int hour;
int minute;
int second;
}proddate;
@interface Goods:nsobject
Here to choose the Set/get memory processing method according to the appropriate situation
Product Name
@property (Nonatomic,retain) nsstring *productname;//(note that the name of the instance variable created here is actually underlined, which has been learned before)
Price
@property (nonatomic,assign) int productprice;
Weight
@property (nonatomic,assign) float productweight;
Product Display picture (picture path)
@property (Nonatomic,retain) NSString *imgurl;
Production date (here is the structure type, without adding the ' * ' number)
@property (nonatomic,assign) proddate producedate;
Expiry date
@property (nonatomic,assign) proddate expiredate;
@end
goods.h*****************************************************
goods.m*****************************************************
#import "Goods.h"
@implementation Goods
-(void) dealloc
{
NSLog (@ "Goods dealloc!");
[_productname release];//because it is a retain type, so the OC object should finally be released in memory once (release is created when new comes out count 1)
[_imgurl release];
[Super Dealloc];
}
@end
goods.m*****************************************************
person.h*****************************************************
#import <Foundation/Foundation.h>
typedef enum {ksexman,ksexwoman,ksexyao}sex;
@interface Person:nsobject
Name
@property (Nonatomic,retain) NSString *name;
Gender (be sure not to use INT type, use enum type)
@property (nonatomic,assign) Sex sex;
Age
@property (nonatomic,assign) int age;
Height
@property (nonatomic,assign) float height;
@end
person.h*****************************************************
person.m****************************************************
#import "Person.h"
@implementation person
-(void) dealloc
{
NSLog (@ "Person dealloc!");
[_name release];
[Super Dealloc];
}
@end
person.m****************************************************
setter.h*****************************************************
#import "Person.h"
#import "Goods.h"
@interface Seller:person
Sellers should have a goods type of parameter, that is, the goods sold
@property (Nonatomic,retain) Goods *goods;
@end
setter.m*****************************************************
#import "Seller.h"
@implementation Seller
-(void) dealloc
{
NSLog (@ "Seller dealloc!");
[_goods release];//corresponds to the goods attribute of @property in seller.
[Super Dealloc];
}
@end
setter.m*****************************************************
buyer.h****************************************************
#import "Person.h"
@interface Buyer:person
The purchaser has no parameters
@end
buyer.h****************************************************
buyer.m****************************************************
#import "Buyer.h"
@implementation Buyer
-(void) dealloc
{
NSLog (@ "Buyer dealloc!");
[Super Dealloc];
}
@end
buyer.m****************************************************
mian.m*****************************************************
#import <Foundation/Foundation.h>
#import "Seller.h"
int main (int argc, const char * argv[]) {
@autoreleasepool {
Seller *seller=[[seller Alloc]init];//seller 1
Goods *g=[[goods alloc]init];//g 1
NSLog (@ "G=%tu", [G retaincount]);//Verify Output G 1
Seller.goods=g;//g 2 (Note that when the instance object seller calls the goods set method, because our goods set method is @property retain type, in the Set method _ Goods (i.e. g) address memory count + 1)
NSLog (@ "G=%tu", [G retaincount]);//Verify Output G 2
[g release];//These two places, because new, so must choose to release G 1
[Seller Release];//seller 0 G 0 (in addition, in Sellter release, the dealloc of the parent class is called, that is, the person's dealloc, so the person is also released once, it will output "person dealloc! " )
}
return 0;
}
main.m*****************************************************
———————————————————————————————————————————
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Objective-c "E-commerce App project-system analysis-detailed comments-code implementation"