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 ...
随机推荐
- 前端面试题整理—ES6篇
1.es5和es6的区别,说一下你所知道的es6 ECMAScript5,即ES5,是ECMAScript的第五次修订,于2009年完成标准化 ECMAScript6,即ES6,是ECMAScript ...
- redis 全局命令 查看所有的键,删除键,检查键是否存在,获取过期时间,键的数据结构类型
Redis有5中数据结构,他们是键值对中的值,对于键来说,有一些通用的命令: 一.查看所有键 keys * 二.获取键总数:dbsize 三.检查键是否存在 exists 如果存在返回1,不存在返回0 ...
- sqlserver 备份脚本
BACKUP DATABASE 数据库名称 TO DISK='d:\3333.bak' ---根据时间生成文件名 --将SQL脚本赋值给变量declare @SqlBackupDataBase as ...
- /*+ hint*/用法,该如何解决
/*+ use_hash(b, a)*/用法SELECT /*+ use_hash(b, a)*/ 1, NVL(b.AgentWorkGroup, ' '), ................ ...
- 缓存dom查询
为了提高性能缓存dom查询; 页面效果:
- Django之CRM项目Day3-客户展示及分页
1.展示客户 模板的查找顺序: 先找全局的templates--> 按照app的注册顺序找templates中的文件 使用admin添加数据: 创建超级用户 python manage.py ...
- 嵌入式4412开发板学习知识-Linux系统基础知识
1. 什么是Linux系统编程 Linux系统编程分为三个部分:系统调用.C库和C编译器. 系统调用系统编程的基础是系统调用,也结束于系统调用.在带有操作系统的嵌入式开发中,需要从操作系统申请一些服务 ...
- luogu P4899 [IOI2018] werewolf 狼火
传送门 首先很显然,从人形起点出发能到的点和狼形能到终点的点都是一个联通块,如果能从起点到终点则说明这两个联通块有交 这个时候可以请出我们的克鲁斯卡尔重构树,即对原图分别建两棵重构树,一棵边权为两端点 ...
- 第28月第3天 c语言读写文件
1. int ConfigIniFile::OpenFile( const char* szFileName ) { FILE *fp; size_t nLen; int nRet; CloseFil ...
- 关于java11 - 应该知道的
Local Variable Type Inference# HTTP Client# Collections# Streams# Optionals# Strings# InputStreams# ...