当前位置:网站首页>Interface oriented programming
Interface oriented programming
2022-07-07 16:41:00 【Mori Ohashi】
- Pre knowledge : What is an interface
- Interface ( english :interface), yes Java An abstract type in programming pre research , Is a collection of abstract methods , A class inherits an interface by way of , So as to realize the abstract method of inherited interface .
- The difference between interfaces and ordinary classes
- Class describes the properties and methods of an object , Interface defines the methods to be implemented by the class
- Interface monthly construction method , Cannot be instantiated , But it can be realized , A class that implements an interface , All methods described in the interface must be implemented , Otherwise, it must be declared as an abstract class .
- There can be variables in the interface , But the variables in the interface will be specified as public static final Variable
- Interface supports multiple inheritance
- The interface is implicitly abstract , Every method in the interface is implicitly abstract , The method in the interface is implicitly specified as public abstract
- The difference between an interface and an abstract class
- Abstract classes can provide partial implementations of certain methods
- Member variables in abstract classes can be of various types , The member variables in an interface can only be public static final type
- Interfaces cannot contain static code blocks and static methods , And abstract classes can .JDK1.8 after , Interfaces can have static methods and method bodies
- A class can only inherit one abstract class , But you can implement multiple interfaces
- Abstract classes are designed to extract some common features or default behaviors of a certain kind , To achieve the purpose of code reuse . The interface is designed to specify a certain standard , It emphasizes norms , The use of polymorphism is embodied in object-oriented language .
- Branch theme
- JDK8 -- Interface default method
- Definition
- Interfaces can have implementations , And you don't need an implementation class to implement its methods , When defining interfaces , Just prefix the method name with default Keyword to implement the default method
- Grammar format
- public interface MyInterface{
- default void print(){
- // I'm the default method
- }
- }
- Conflict resolution
- Problem description : If a class inherits multiple interfaces , The default method with the same name is defined inside these interfaces
- 1) The method in the class has the highest priority . A method declared in a class or parent class takes precedence over any method declared as the default .
- 2) If you can't judge according to the first article , Then the sub interface has the highest priority : Function signatures are the same , The interface with the most specific implementation default method is preferred , That is, if B Inherited A, that B Just like A More specific .
- 3) Last , If you still can't judge , Classes that inherit multiple interfaces must override and call the desired methods by displaying , The displayed selection uses the implementation of which default method .
- Definition
- JDK8-- Interface declaration static method
- Grammar format
- public interface Vehicle {
- default void defaultMethod(){
- System.out.println(' I'm the default method !');
- }
- // Static methods
- static void staticMethod(){
- System.out.println(' I'm a static method !!!');
- }
- }
- Grammar format
- Pre knowledge : Process oriented programming POP
- It's a process centric programming idea , Analyze the steps needed to solve the problem , Then use functions to implement these steps step by step , When using, call one by one until the problem is solved
- advantage
- Break the problem down into steps 、 Like an assembly line , Step by step , Process and simplify complex problems . Higher performance than object-oriented programming , In object-oriented programming, the class calling process needs to load 、 Instantiation , Greater resource consumption ; High performance requirements, such as single chip microcomputer 、 Embedded development 、 Linux/Unix Process oriented development is generally adopted for
- shortcoming
- No object-oriented programming, easy to maintain 、 Easy to reuse 、 Easy to expand
- Applicable scenario
- In the development of systems with high performance requirements
- Pre knowledge : object-oriented programming OOP
- Object oriented programming is an object-oriented programming idea , By analyzing the problem , Decompose objects one by one , Object contains specific properties and behaviors , Then through the calls between different objects to solve the problem .
- advantage
- 1) Easy to understand : Adopt the object-oriented idea to design and develop , More in line with people's way of thinking , High readability .
- 2) Easy maintenance : Object oriented has encapsulation 、 Inherit 、 Characteristics of polymorphism , Even if the demand changes , More local modules need to be maintained , Easier and cheaper to maintain .
- 3) Easy to expand : Object oriented has encapsulation 、 Inherit 、 Characteristics of polymorphism , High cohesion can be designed in the system design stage 、 Low coupling system structure , Make the system more flexible 、 It's easier to expand .
- 4) Easy to reuse : It's the same thing , Because of the three characteristics of object-oriented , So that the general code can be reused more simply , Improve development efficiency .
- shortcoming
- Performance will be lower than process oriented , Programming complexity is high
- Applicable scenario
- User needs change all the time , Internet applications , game , Enterprise internal application
- What is interface oriented programming
- Interface oriented programming (Interface Oriented Programming:OIP) It's a kind of programming idea , Interface is a form of entity abstraction , It is used to separate the internal implementation for external communication , Ultimately, internal changes are implemented without affecting external interaction with other implementations
边栏推荐
猜你喜欢
Xcode Revoke certificate
The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
值得一看,面试考点与面试技巧
AutoLISP series (1): function function 1
Unity3d click events added to 3D objects in the scene
ByteDance Android gold, silver and four analysis, Android interview question app
time标准库
字节跳动Android面试,知识点总结+面试题解析
使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑
预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
随机推荐
Vs2019 configuration matrix library eigen
3000 words speak through HTTP cache
记一次项目的迁移过程
Balanced binary tree (AVL)
Binary search tree (features)
[hcsd celebrity live broadcast] teach the interview tips of big companies in person - brief notes
【DesignMode】代理模式(proxy pattern)
作为Android开发程序员,android高级面试
[Android -- data storage] use SQLite to store data
JS中null NaN undefined这三个值有什么区别
Performance measure of classification model
What else can an ordinary person do besides working in a factory to make money?
掌握这个提升路径,面试资料分享
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
低代码(lowcode)帮助运输公司增强供应链管理的4种方式
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
[designmode] template method pattern
Opencv configuration 2019vs
【知识小结】PHP使用svn笔记总结
The difference and working principle between compiler and interpreter