Individual Reading Assignment

理解面向对象编程的核心原则:隐藏实现细节的重要性
本文深入探讨了在编程中隐藏实现细节的重要性。通过详细分析这一原则的五个关键优势,包括减少全局影响、提升性能、增强代码可读性和维护性,以及促进代码的自我解释性,阐述了为什么隐藏实现细节比暴露它们更有利于软件开发。此外,文章还讨论了如何在非面向对象环境中应用面向对象技术,提供了几种实用的方法,以及如何在继承时避免冗余功能,同时给出了实现良好封装的一系列技巧和建议。

Problems: 

1.Why it is better to hide implementation details than expose them.

  1.1 Changes don't affect the whols program.

  1.2 It is easier to improve performance.

  1.3 It will be easier to check codes and more confident to bilieve it is right.

  1.4 The program becomse more self-documenting.

  1.5 You don't have to pass data all over the program.

2.Do simple items need to be treated as ADTs?

  Yes. You don't have to have a formidable data type to justify using an abstract data type. For example, a Light class which only has routines TurnOn and TurnOff is also a good ADT. You might think that it would be a waste to isolate simple "on" and "off" operations in routines of their own, but even simple operations can benefit from the use of ADTs. Putting the light and its operations into an ADT makes the code more self-documenting and easier to change, confines the potential consequences of changes to the TurnLightOn() and TurnLight-Off() routines, and reduces the number of data items you have to pass around.

3.How can object oriented technology be used in a non-object-oriented environment?

  3.1 Pass ID to each routine.

  3.2 Explicitly provide the data used by the ADT services. In this approach, you declare the data that the ADT uses within each routine that uses an ADT service. 

  3.3 Use implicit instances (with great care) by something like SetCurrentXX(XXID).

4.Should a inhertion expose redunda functions?

  No. It fails the main test for inheritance, which is, "Is inheritance used only for "is a" relationships?" 

5.What tips make a good encapsulation?

  5.1 Minimize accessibility of classes and members  

  5.2 Don't expose member data in public

  5.3 Avoid putting private implementation details into a class's interface

  5.4 Don't make assumptions about the class's users

  5.5 Avoid friend classes

  5.6 Don't put a routine into the public interface just because it uses only public routines

  5.7 Favor read-time convenience to write-time convenience

  5.8 Be very, very wary of semantic violations of encapsulation

 

转载于:https://www.cnblogs.com/buaasts/p/4024980.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值