how to avoid inheritance abuse
Liskov Principle: if S is a subtype of Type T, then any objects of type T may be repalced by objects of type S without altering any of the properties of T;
that is, if B inherits from A, then B should be a A!!!
usaully we adopt inheritance for two reason:
1) interface (for polymorphism)
2) implementation (for code reuse)
if it's for implementtation, coposition is good enough for it;
as used in most design patten, we commenly use two layers of inheritance, interface and its implementation.
with good design, we seldom more than 3 or 4 layers
how to avoid inheritance abuse的更多相关文章
- 10 Tips for Writing Better Code (阅读理解)
出发点 http://www.tuicool.com/articles/A7VrE33 阅读中文版本<编写质优代码的十个技巧>,对于我编码十年的经验,也有相同感受, 太多的坑趟过,太多的经 ...
- 【8.0.0_r4】AMS分析(十七)(ActivityManagerService.java下)
代码位于frameworks/base/services/core/java/com/android/server/am/,一共有七十个文件. Java源码位于package com.android. ...
- Effective Java 16 Favor composition over inheritance
Inheritance disadvantage Unlike method invocation, inheritance violates encapsulation. Since you don ...
- Think Python - Chapter 18 - Inheritance
In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...
- [转载]Spring Bean Configuration Inheritance
转自: http://www.mkyong.com/spring/spring-bean-configuration-inheritance/ In Spring, the inheritance i ...
- Spring bean configuration inheritance
In Spring, the inheritance is supported in bean configuration for a bean to share common values, pro ...
- Classical Inheritance in JavaScript
JavaScript is a class-free, object-oriented language, and as such, it uses prototypal inheritance in ...
- Memory Layout for Multiple and Virtual Inheritance
Memory Layout for Multiple and Virtual Inheritance(By Edsko de Vries, January 2006)Warning. This art ...
- <Effective C++>读书摘要--Inheritance and Object-Oriented Design<二>
<Item 36> Never redefine an inherited non-virtual function 1.如下代码通过不同指针调用同一个对象的同一个函数会产生不同的行为Th ...
随机推荐
- java中变量关系
- iOS拍照图片旋转的问题
很久之前,遇到了这种情况,iOS某端拍照上传到服务器,其他iOS端从服务器下载该照片展示,发现图片逆时针旋转了90度.当时百度了一下,找到一段代码修正image方向,问题解决了,但没有深入理解底层原理 ...
- linux(Cnetos7)安装jdk和tomcatmysql,tomcat
mysqllinux版本的地址 安装包下载 下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-1.el6.x86_64.rp ...
- C++ 窗口
DestroyWindow(); //销毁窗口 可重载的事件: PostNcDestroy 窗口销毁后调用
- ue4 编辑器记录
Matinee 编辑器 菜单:Add New Empty Group->选择要变动的Actor->菜单:Add Actor->菜单:Add Key->变更Actor属性-> ...
- 第25月第4天 Blog-API-with-Django-Rest-Framework项目记录01
#------------------------------ 1. djangochinaorg项目 https://github.com/DjangoChinaOrg/Django-China-A ...
- sql server 2008 windows验证改混合登陆中SqlServer身份验证用户名密码
安装过程中,SQL Server 数据库引擎设置为 Windows 身份验证模式或 SQL Server 和 Windows 身份验证模式.本主题介绍如何在安装后更改安全模式. 如果在安装过程中选择“ ...
- response的字节流和字符流输入的区别和问题--02-response的outputStream输出数据的问题.avi
02-response的outputStream输出数据的问题.avi; [字节流] 用meta标签 第一段原始代码:写错: 03-response的Writer输出数据的问题.avi;[字符流输出] ...
- 清除redis缓存
redis-cli -p 6379(指定进入端口号为6379的redis数据库)1.清空当前redis数据库缓存flushdb 2.清空整个redis缓存flushall
- Javascript - ExtJs - GridPanel组件 - 编辑
GridPanel组件 - 编辑 Ext.grid.plugin.Editing 如果要对表格使用列编辑器控件,则需要完成以下几步 1.将columns中需要编辑的列设为editor并提供编辑列时所要 ...