当前位置:网站首页>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
边栏推荐
- 水平垂直居中 方法 和兼容
- 01tire+ chain forward star +dfs+ greedy exercise one
- 模拟Servlet的本质
- 低代码(lowcode)帮助运输公司增强供应链管理的4种方式
- Odoo integrated plausible embedded code monitoring platform
- AutoLISP series (2): function function 2
- JS中null NaN undefined这三个值有什么区别
- AutoLISP series (3): function function 3
- [C language] question set of X
- Vs tool word highlight with margin
猜你喜欢
字节跳动Android面试,知识点总结+面试题解析
值得一看,面试考点与面试技巧
Imitate the choice of enterprise wechat conference room
Pycharm terminal enables virtual environment
As an Android Developer programmer, Android advanced interview
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
Unity3d click events added to 3D objects in the scene
HAVE FUN | “飞船计划”活动最新进展
"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
随机推荐
three. JS create cool snow effect
Three. JS series (2): API structure diagram-2
模拟Servlet的本质
偶然升职的内心独白
laravel构造函数和中间件执行顺序问题
Unity3d click events added to 3D objects in the scene
Pycharm terminal enables virtual environment
47_ Contour lookup in opencv cv:: findcontours()
ATM system
Introduction to ThinkPHP URL routing
水平垂直居中 方法 和兼容
掌握这个提升路径,面试资料分享
预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
二叉搜索树(特性篇)
pycharm 终端部启用虚拟环境
Prometheus API deletes all data of a specified job
Sysom case analysis: where is the missing memory| Dragon lizard Technology
Balanced binary tree (AVL)
Performance measure of classification model
【DesignMode】享元模式(Flyweight Pattern)