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 ...
随机推荐
- Node.js学习入门
Node.js是什么 Node.js是一个可以允许我们在服务器端运行JavaScript代码的程序. 这是什么意思呢?通常,我们写的JavaScript代码都是在浏览器中运行的. 实际上,浏览器就是一 ...
- Silverlight分页
对于分页,首先要明确一些高效率的策略: 1.一次获取还是每次获取一页的数据 既然考虑了分页,肯定是数据量大,大到不能一页来显示,可能会很多页,我的做法更倾向于,首先要考虑用户可能看的页数,就是说用户可 ...
- Ajax和Json实现自动补全
1.index.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...
- impala系列:impala特有的操作符
--=======================Impala 特有的操作符--=======================ILIKE 操作符, 忽略大小写的 like 操作符.REGEXP 操作符 ...
- Chrome 浏览器快捷键
Ø 前言 记录下 Chrome 的快捷键,原文链接:http://www.cnblogs.com/mikalshao/archive/2010/11/03/1868568.html 1. 标 ...
- 四十、Linux 线程——互斥锁和读写锁
40.1 互斥锁 40.1.1 介绍 互斥锁(mutex)是一种简单的加锁的方法来控制对共享资源的访问. 在同一时刻只能有一个线程掌握某个互斥锁,拥有上锁状态的线程能够对共享资源进行访问. 若其他线程 ...
- 另一种的SQL注入和DNS结合的技巧
这个技巧有些另类,当时某业界大佬提点了一下.当时真的真的没有理解到那种程度,现在可能也是没有理解到,但是我会努力. 本文章是理解于:http://netsecurity.51cto.com/art/2 ...
- asp.net mvc5 多语言应用
需求:有些网站需要多语言显示,比如简体中文,繁体中文,英文. 1.创建一个mvc项目: 2.创建App_GlobalResources 创建了中文.英文两个语言的资源文件,中文是程序的默认语言,所以我 ...
- fail2ban 防爆破,防止CC 攻击
fail2ban fail2ban监视检测日志文件,根据匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作. 可用来放置爆破 和 CC 攻击. 安装: yum install fail2ban -y ...
- Jvm 性能检测
一.Jmap 1.查看整个LVM 内存状态jmap -heap pid 2.查看JVM堆中对象详细占用情况jmap -histo [pid] 3.导出整个JVM 中内存信息jmap -dump:fo ...