1、编程语言中的架构思考Dont Believe Me!Composition over inheritance?Does Golang need dependency injection?Do we need a complete interface?OOPInheritanceInheritanceInheritance is the mechanism of basing an object or class upon another object(prototypical inheritance)or class(class-based inheritance),retaining sim
2、ilar implementation.What is the role of inheritance?Code Reuse/DRY?When to use inheritance?IS-A?Java Standard LibraryStackMethods inherited from class java.util.Vector add,add,addAll,addAll,addElement,capacity,clear,clone,contains,containsAll,copyInto,elementAt,elements,ensureCapacity,equals,firstEl
3、ement,get,hashCode,indexOf,indexOf,insertElementAt,isEmpty,iterator,lastElement,lastIndexOf,lastIndexOf,listIterator,listIterator,remove,remove,removeAll,removeAllElements,removeElement,removeElementAt,removeRange,retainAll,set,setElementAt,setSize,size,subList,toArray,toArray,toString,trimToSizecla
4、ss Bird(object):name=Bird def fly(self):print(self.name+can fly)def lay(self):print(self.name+can lay)def run(self):print(self.name+can run)class Ostrich(Bird):name=Ostrich def swim(self):print(self.name+can swim)Inheritance break Encapsulationclass Bird(object):name=Bird def fly(self):pass def lay(
5、self):print(self.name+lay)def run(self):print(self.name+run)class Ostrich(Bird):name=Ostrich def fly(self):raise Exception(self.name+cant fly)class Goddess(self):name=Goddess def pray(self):print(self.name+pray)def release_bird(self,bird):self.pray()bird.fly()class Goddess(self):name=Goddess def pra
6、y(self):print(self.name+pray)def release_bird(self,bird):self.pray()if isinstance(bird,Ostrich):bird.run()else:bird.fly()Liskov substitution principleWhat is wanted here is something like the following substitution property:If for each object o1 of type S there is an object o2 of type T such that fo