当前位置:网站首页>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

边栏推荐
- Personal notes of graphics (2)
- three.js打造酷炫下雪效果
- "The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
- Horizontal and vertical centering method and compatibility
- Opencv personal notes
- The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
- HAVE FUN | “飞船计划”活动最新进展
- 记录Servlet学习时的一次乱码
- 掌握这个提升路径,面试资料分享
- Asyncio concept and usage
猜你喜欢

Advanced C language -- function pointer
ByteDance Android gold, silver and four analysis, Android interview question app

Description of vs common shortcut keys

Odoo integrated plausible embedded code monitoring platform

pycharm 终端部启用虚拟环境

如何快速检查钢网开口面积比是否符合 IPC7525

Three. JS series (2): API structure diagram-2

time标准库
As an Android Developer programmer, Android advanced interview

Personal notes of graphics (2)
随机推荐
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
URL和URI的关系
01tire+ chain forward star +dfs+ greedy exercise one
"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
[C language] question set of X
three. JS create cool snow effect
DNS 系列(一):为什么更新了 DNS 记录不生效?
Set the route and optimize the URL in thinkphp3.2.3
[medical segmentation] attention Unet
Three. JS series (1): API structure diagram-1
面向接口编程
修改配置文件后tidb无法启动
Prediction - Grey Prediction
打造All-in-One应用开发平台,轻流树立无代码行业标杆
AutoLISP series (2): function function 2
Prometheus API deletes all data of a specified job
Markdown formula editing tutorial
两类更新丢失及解决办法
LocalStorage和SessionStorage