跳到主要內容

發表文章

目前顯示的是有「OOP」標籤的文章

Distributed transactions

Table of contents [ hide ] Basic theory  CAP States that any distributed data store can provide only two of the following three guarantees. Consistency Every read receives the most recent write or an error. Availability Every request receives a (non-error) response, without the guarantee that it contains the most recent write. Partition tolerance The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes. Typical architecture of distributed systems When a network partition failure happens, it must be decided  whether to do one of the following: CP: cancel the operation and thus decrease the availability but ensure consistency AP: proceed with the operation and thus provide availability but risk inconsistency. BASE Basically-available, soft-state, eventual consistency. Base theory is the practical application of CAP theory, that is, under the premise of the existence of partitions and copies, through certain syste

Proxy

Table of contents [ hide ] Proxy in design pattern The proxy pattern is a software design pattern, as a wrapper or agent object that is being called by the client to access the real serving object behind the scene. There are two advantages: Provides access control for real objects. Provides additional functionality when accessing real objects. And there are two types of proxy: Static proxy: proxies are created manually. Java example on  GitHub . Dynamic proxy: proxies are created by JDK Proxy or CGLib Proxy with reflection. JDK proxy Before the proxy object is created, it must implement the invoke method of the InvocationHandler, which is invasive to the target object. JDK Dynamic proxy can only proxy by the interface (so your target class needs to implement an interface, which is then also implemented by the proxy class) CGLib proxy The proxy object is created by implementing the intercept method of MethodInterceptor, and the target object does not need to implement this metho

IOC and AOP

Table of contents [ hide ] The famous two features of Spring are IOC and AOP. Inversion of Control It uses the Spring's container to help us get objects, and the Spring manages these objects. There are two main types: Dependency Lookup: The Inversion of Control is limited to the container invoking callback methods that the application code can use to obtain resources. Dependency Injection:  The container is wholly responsible for wiring up components, and passing resolved objects into JavaBean properties or constructors for application. Aspect-Oriented Programming It helps to add new business logic across different modules without modifying the current code. reference: https://zhuanlan.zhihu.com/p/136474190 https://www.jianshu.com/p/7a1c0bad2708

Composition and Inheritance

Composition vs Inheritance In "Effective JAVA" or if you search the Internet, you will find that everyone says that composition is better than inheritance. We know the composition has the advantages of the following: Composition is loosely coupled. The composition has better access control.  Composition is more flexible. Unit test easier. Is this really true? usually yes, but let's back to thinking about it, what are we programmed for, methods are just tools, and people are the core. Let's see what the advantage is of inheritance before we choose the methods. here . Choosing the best fit method for the program is the most important thing, not just avoiding inheritance. reference: https://www.digitalocean.com/community/tutorials/composition-vs-inheritance https://github.com/hollischuang/toBeTopJavaer

SOLID

SOLID is the fundamental and core principle of OOP. Single-Responsibility Principle High cohesion: A module preferably has only one business logic. Low coupling:   The different modules work independently and are connected by simple protocols to minimize side effects. Open-Closed Principle Open for extension:  It is easy to extend new functions with existing code. Close for modification:  Do not modify existing classes to ensure stable functions. Liskov-Substitution Principle A superclass should be replaceable with objects of its subclasses without breaking the application. Interface-Segregation Principle Clients only depend on the interfaces they need, don't use the "big" interface to contain everything. Dependence-Inversion Principle The program should depend upon abstractions, not concretions. reference: https://en.wikipedia.org/wiki/SOLID https://blog.knoldus.com/what-is-liskov-substitution-principle-lsp-with-real-world-examples/ https://github.com/hollischuang/toBeTo

Three major features of object-oriented

Table of contents [ hide ] Encapsulation Encapsulation is the process of enclosing all critical information inside,  the public method is the only way for other objects to access the data. The advantages are as follows: It protects data and implementation details through access restrictions, and users can only get results without modifying the objects inside. It is easy to change the implementation according to requirements because it does not expose the implementation details to the users. Inheritance It uses all the features of the parent class and extends the new features itself. The advantages are as follows: It reuses the same code. It restricts all child objects to the same business logic as the parent object, but they do not affect each other. Polymorphism It executes methods differently by overriding the parent method, especially when the same business logic runs different methods at runtime. There are two types of Polymorphism: Method override. Method overloading. referen