Classes(1)

Good Encapsulation
1. Minimiza accessibility of classes and members.
2. Don't expose member data in public.
3. Don't put private implementation details in a class's interface
4. Favor read-time convenience to write-time convenience.
Code is read far more times than it's written, even during initial development.
5.Be very, very wary of semantic violaions of encapsulation.
Here are some examples of the ways that a user of a class can break encapsulation semantically:
Not calling Class A's initialize() routine because you know that Class A's performFirstOperation() routine calls it automatically.
Not calling the database.connect() routine before you call employee.retrieve(database) because you know that the employee.retrieve() function will connect to the database if there isn't already a connection.
The proble with each of these examples is that they make the client code dependent not on the class's public interface, but on its private implementation.  Anytime you find yourself looking at a class's implementation to figure out how to use the class, you're not programming to the interface; you're programming through the interface to the implementation.
6. Watch for coupling that's too tight.

Design and Implementation Issues
Summary of when to use inheritance and when to use containment:
1. if multiple classes share common data but not behavior, then create a common object that those classes can contian.
2. if multiple classes share common behavior but not data, then derive them from a common base class that defines the common routines.
3. if multiple classes share common data and behavior, then inherit from a common base class that defines the common data and routines.
4. inherit when you want the base class to control your interface; contain when you want to control your interface.

 

翻译每行代码的意思 def IOU(boxes, classes, scores, controlRectangle, controlInvalid, url): # numpy转list boxes = boxes.tolist() classes = classes.tolist() scores = scores.tolist() # 读取配置文件 if os.path.exists('stream_dict.txt'): with open('stream_dict.txt', 'r') as f: stream_dict = json.load(f) else: stream_dict = {} if os.path.exists('cameraId_dict.txt'): with open('cameraId_dict.txt', 'r') as f: cameraId_dict = json.load(f) else: cameraId_dict = {} cameraId = cameraId_dict[url] try: w = int(stream_dict[cameraId][1].split(',')[0]) h = int(stream_dict[cameraId][1].split(',')[1]) except: w = 1920 h = 1080 h1 = (w - h) * 0.5 / w * 640 img_h = 640 - h1 * 2 if controlRectangle == [] and controlInvalid == []: boxes1 = boxes classes1 = classes scores1 = scores if controlRectangle != []: boxes1 = [] classes1 = [] scores1 = [] for i in range(len(boxes)): for j in range(len(controlRectangle)): a = boxes[i] c = classes[i] s = scores[i] x1 = a[0] y1 = a[1] x2 = a[2] y2 = a[3] d = [x1, y1, x2, y2, x2, y1, x1, y2] b = [controlRectangle[j][0]*640, h1 + controlRectangle[j][1]*img_h, controlRectangle[j][2]*640, h1 + controlRectangle[j][3]*img_h, controlRectangle[j][4]*640, h1 + controlRectangle[j][5]*img_h, controlRectangle[j][6]*640, h1 + controlRectangle[j][7]*img_h] iou = calculate_iou(d, b) if iou > 0: boxes1.append(a) classes1.append(c) scores1.append(s) break else: boxes1 = boxes classes1 = classes scores1 = scores if controlInvalid != []: boxes2 = copy.deepcopy(boxes1) classes2 = copy.deepcopy(classes1) scores2 = copy.deepcopy(scores1) for i in range(len(boxes2)): for j in range(len(controlInvalid)): a = boxes2[i] c = classes2[i] s = scores2[i] x1 = a[0] y1 = a[1] x2 = a[2] y2 = a[3] d = [x1, y1, x2, y2, x2, y1, x1, y2] b = [controlInvalid[j][0]*640, h1 + controlInvalid[j][1]*img_h, controlInvalid[j][2]*640, h1 + controlInvalid[j][3]*img_h, controlInvalid[j][4]*640, h1 + controlInvalid[j][5]*img_h, controlInvalid[j][6]*640, h1 + controlInvalid[j][7]*img_h] iou = calculate_iou(d, b) if iou > 0: del boxes1[i] del classes1[i] del scores1[i] break boxes1 = np.array(boxes1) classes1 = np.array(classes1) scores1 = np.array(scores1) return boxes1, classes1, scores1
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值