黑马程序员--OC自学笔记---07@property使用之电商app练习

------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;
}
 

//结果截图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陌影~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值