![]() Principle of single function : Avoid spreading the same responsibilities into different classes. LSP Principles enable us to correctly design a reasonable object inheritance design 、 Reasonably apply Abstract mechanisms. Richter's principle of substitution : Subtypes must be able to replace their parent type 、 And appear wherever the parent class can appear. Closure refers to the extension of the function of the module, It should not affect or affect existing program modules on a large scale, But by adding new classes to extend the function. Opening and closing principle : The developed module must be open, Support extended, Not rigid. What are the principles of object-oriented design 1. Rewrite : Occurs in a parent-child class, Method name 、 The parameter list must be the same, The return value type is equal to the parent class, Exception thrown is less than or equal to parent class, Access modifier greater than or equal to parent class Method overloading 、 Method overrides the difference between them heavy load : Occurs in a class, Same method name, Different parameter list, Independent of method return values and access modifiers, That is, overloaded methods cannot be distinguished according to the return type wait() Method has been waiting for, Until the lock is obtained or interrupted getClass final Method, Get runtime type wait Make the current thread wait for the lock of the object, The current thread must be the owner of the object, That is, the lock with the object hashCode This method is used for hash lookup, Rewrote equals Methods are usually rewritten equals stay Object China and = It's the same, Subclasses generally need to override this method clone Protection method, Implement shallow copy of objects, Only when Cloneable Interface to call this method, Otherwise throw CloneNotSupportedException abnormal Object What are the public methods in Object Is the parent of all classes, Any class inherits by default Object Member method : Look at the parent class during compilation, Look at subclasses during operationĬollection and Collections The difference between Collection Is the parent interface of a collection class, The interface between inheritance and him mainly includes Set and ListĬollections Is a help class for collection classes, He provides a series of static methods for searching various collections 、 Sort 、 Thread safety and other operations Member variables : Both compilation and runtime depend on the parent classģ. Members of a parent class can only be accessed using a reference to the parent classĢ. Simplicity : Polymorphism simplifies the process of writing and modifying the code of application software, Especially when dealing with the operation and operation of a large number of objects, This feature is particularly prominent and importantġ. flexibility : It embodies flexible and diverse operations in the application, Improve the efficiency of useĥ. ![]() Interface : When polymorphic, superclasses provide a public interface to subclasses through method signatures, Implemented by subclasses to perfect or cover itĤ. Extensibility : The added subclasses do not affect the operation of the features of the existing classesģ. Replaceability, Polymorphism is replaceable for an existing codeĢ. Meet three conditions : Have inherited 、 There's rewriting 、 There are parent class references to child class objectsġ. That is to say, the same message can adopt different behavior modes according to different sending objectsĪ reference to a supertype points to an object of a subtype Inheritance makes multiple classes have child parent relationships, When a class has multiple subclasses, If the parent class changes, Then these subclasses will change together, Cause between classes “ Strong coupling ” Relationship Make the inheritance relationship between classes exist, Is the premise of realizing polymorphic operation ![]() Reduce the amount of code, It can improve the reuse rateĢ. therefore, A subclass is a specialized version of the parent class, It inherits all instance variables and methods defined in the parent class, And added unique elements. Stay JAVA in, The inherited class is called the parent class (parent class) Or superclass (superclass), A class that inherits a parent class is called a subclass (subclass) Or derived class (derivedclass). Use variables, etc private modification, Or encapsulated in the method, Make it inaccessible directly, Increased access steps and difficulty stay getter/setter Add property control statement to method ( Used to judge the validity of attribute values ) Write the corresponding getter/setter Method ( For reading and writing properties ) ģ. Privatize member variables ( Use private modification ) Ģ. Three characteristics of object orientationĮncapsulation is to put the commonness of the same kind of things ( Include properties and methods ) Fall into the same category, Easy to use.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |