当前位置:网站首页>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
边栏推荐
- 偶然升职的内心独白
- Binary search tree (basic operation)
- ORACLE进阶(六)ORACLE expdp/impdp详解
- Spark Tuning (III): persistence reduces secondary queries
- 【医学分割】attention-unet
- Have fun | latest progress of "spacecraft program" activities
- php 自带过滤和转义函数
- Inner monologue of accidental promotion
- 在哪个期货公司开期货户最安全?
- PHP realizes wechat applet face recognition and face brushing login function
猜你喜欢
平衡二叉树(AVL)
两类更新丢失及解决办法
The difference and working principle between compiler and interpreter
Advanced C language -- function pointer
Personal notes of graphics (2)
[Android -- data storage] use SQLite to store data
值得一看,面试考点与面试技巧
Personal notes of graphics (1)
DNS 系列(一):为什么更新了 DNS 记录不生效?
AutoLISP series (2): function function 2
随机推荐
Inner monologue of accidental promotion
Unity3d click events added to 3D objects in the scene
【DesignMode】代理模式(proxy pattern)
Pycharm terminal enables virtual environment
ORACLE进阶(六)ORACLE expdp/impdp详解
URL和URI的关系
如何快速检查钢网开口面积比是否符合 IPC7525
SqlServer2014+: 创建表的同时创建索引
[vulnhub range] thales:1
【DesignMode】模板方法模式(Template method pattern)
Statistical learning method -- perceptron
3000 words speak through HTTP cache
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
As an Android Developer programmer, Android advanced interview
[C language] question set of X
PHP实现微信小程序人脸识别刷脸登录功能
删除 console 语句引发的惨案
预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
Tragedy caused by deleting the console statement
Geoserver2.18 series (5): connect to SQLSERVER database