design rules

This article will be continuously improved.

1. Dependencies.  Dependencies are very important for both implementing and understanding of code.  A class needs help from other classes, and it is surely be needed by some other classes.  A natural but bad idea is to let these classes call each other.  If you program in this way, then your design is rotting.  Even you yourself cannot touch the code after some period and nobody wants to maintain your code or fix your bugs.  The way to avoid it is to use abstracts.  You need some help? OK, imagine what the help should be and write an abstract class.  If you always use this technology then your code will be easier to read and modify.

2. Classes.  Class is a bunch of code that servers as an employee that holding some properties and can do some minor jobs based on the properties.  If you want it to do something, you have to first give it the property.  Think of a truck driver.  Without a truck, the driver cannot send tons of products to places far away.  With the truck, the driver can do the job but even then the driver actually relies on the truck to do the job, the driver himself just takes care of the truck.  So this is a very different view according to structure programming.  When thinking in structure, you think about the hard problems that how to do the job.  When thinking OO, you think about if I have a property, what I would do.  It's a lot easier.  Defining classes is art.  It's usually helpful to have a mental model before defining classes.  If you are modelling a real system, then define major classes by separating the players.  After that you may want to define some process to be class, too.  And then you can modify the classes to meet OO principles.  It may take you several hours to write the code that can be finished in 10 minutes.  But when you are familiar with that, it will be easier.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值