原创 2004年09月19日 17:30:00

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.



博客一: 1. 问题的产生原因            "类1 can't find referenced class 类2" 字面上的意思就是类1找不到类2的引用;接着再看下去"You may ne...
  • xiangjai
  • xiangjai
  • 2014年01月10日 14:11
  • 14199

学习笔记 自动搜索

#宏函数my-dir返回编译系统提供的当前路径,即Android.mk的目录 #如(HelloWorld/ LOCAL_PATH := $(call my-di...
  • u013340539
  • u013340539
  • 2014年07月15日 21:32
  • 2027

Spring Boot 学习(一) 快速搭建SpringBoot 项目

快速搭建一个 Spring Boot 项目 部分参考于《深入实践Spring Boot》、《Spring实战 第四版》与程序猿DD的有关博客。...
  • u011244202
  • u011244202
  • 2017年01月18日 20:42
  • 1274

jxl.jar ,jspupload.jar,classes12.jar,poi-2[1].5.1-final-20040804.jar

  • 2010年06月22日 16:40
  • 2.39MB
  • 下载


  • 2015年12月10日 15:01
  • 2.5MB
  • 下载

安卓逆向学习笔记(1) - 反编译classes.dex获取apk的java源代码

  • pengyan0812
  • pengyan0812
  • 2015年01月15日 14:35
  • 12361

FaceID-1:Deep Learning Face Representation from Predicting 10,000 Classes 笔记

  • kunyXu
  • kunyXu
  • 2017年01月12日 11:21
  • 250

JAVA 复习(Think In Java, 4th) -- Inner Classes - Part1

public class EasyInnerClass { private People list[] = null; private int count = 0; publi...
  • shanwu1985
  • shanwu1985
  • 2014年09月23日 07:47
  • 498

安卓逆向学习笔记(1) - 反编译classes.dex获取apk的java源代码

原文地址: 在上一篇文章安卓逆向学习笔记(0)中,我记录...
  • 2017年07月03日 09:33
  • 294

Part1:A Brief Study of Classes and Object-oriented Programming.

Actionscript 3.0 PV3d papervision3d OOP
  • pdcxs
  • pdcxs
  • 2011年07月15日 18:11
  • 74