------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
//@property的使用之电商app练习
//Goods类
#import<Foundation/Foundation.h>
typedef structT{
int hour;
int min;
int sec;
}MyTime;
typedef structD{
int year;
int month;
int day;
MyTime time;
}MyDate;
@interface Goods: NSObject
/*
商品名称
单价
重量
商品展示图片
生产日期(暂时用结构体表示)produceDate
过期时间expireDate
*/
@property(nonatomic,retain)NSString *productName;
@property(nonatomic,assign)float productPrice;
@property (nonatomic,assign)floatproductWeight;
@property(nonatomic,retain)NSString *productImage;
@property(nonatomic,assign)MyDate produceDate;
@property(nonatomic,assign)MyDate expireDate;
@end
#import"Goods.h"
@implementationGoods
- (void)dealloc
{
NSLog(@"Goods dealloc");
[_productName release];
[_productImage release];
[super dealloc];
}
@end
//Person类
#import<Foundation/Foundation.h>
typedef enumsex{kSexMan,kSexWoman}iSex;
@interfacePerson : NSObject
//姓名
@property(nonatomic,retain)NSString *name;
//性别
@property(nonatomic,assign)iSex sex;
//年龄
@property(nonatomic,assign)int age;
//身高
@property(nonatomic,assign)float height;
@end
#import"Person.h"
@implementationPerson
- (void)dealloc
{
NSLog(@"person dealloc");
[_name release];
[super dealloc];
}
@end
//Seller 类
#import"Person.h"
#import"Goods.h"
@interfaceSeller : Person
@property(nonatomic,retain)Goods *goods;
@end
#import"Seller.h"
@implementationSeller
- (void)dealloc
{
[_goods release];
NSLog(@"seller dealloc");
[super dealloc];
}
@end
//Buyer类
#import"Person.h"
@interface Buyer: Person
@end
#import"Buyer.h"
@implementationBuyer
- (void)dealloc
{
NSLog(@"buyer dealloc");
[super dealloc];
}
@end
//主函数
#import <Foundation/Foundation.h>
#import"Person.h"
#import"Buyer.h"
#import"Seller.h"
int main(intargc, const char * argv[]) {
@autoreleasepool {
Person *person = [Person new];
[person release];
Buyer *buyer =[Buyer new];
[buyer release];
Goods *g = [Goods new];
Seller *seller = [Seller new];
seller.goods = g;
[g release];
[seller release];
}
return 0;
}
//结果截图