当前位置:网站首页>Interface learning
Interface learning
2022-07-03 06:46:00 【Xiao Xie Bu touch Yu】
interface
- General class : Only concrete implementation
- abstract class : Specific implementation and specification ( Abstract method ) There are !
- Interface : Only norms ! I can't write by myself , Professional constraints
- Interface is specification , It defines a set of rules , In the real world “ If you are … Must be able to …” Thought . If you are an angel , Must be able to fly . If you are a car , You have to be able to run . If you're a good person , You have to get rid of the bad guys ; If you are a bad person , You have to bully good people .
- The essence of an interface is a contract , Just like the law of our world . When it's done, everyone follows .
OO The essence of , It's the abstraction of objects , The best way to do this is through interfaces . Why do we talk about design Patterns are only for languages with abstract capabilities ( such as c++、java、c# etc. ), It's because of the design pattern , In fact, it's how to abstract reasonably . - The keyword of the declaration class is class, The key to declare the interface is interface
package com.oop.Demo08;
//interface Defined keywords , Interfaces need to have implementation classes
public interface UserService {
// Definition public static final
public static final int age = 99;
// All definitions in an interface are actually abstract public abstract
public abstract void add(String name);
void delete(String name);
void update(String name);
void query(String name);
// Interface function
/* 1. constraint 2. Define some methods Let different people realize 3. public abstract 4.public static final 5. Interface cannot be instantiated There is no constructor in the interface 6.implements Multiple interfaces can be implemented 7. You have to override the methods in the interface * */
}
==========================================================
package com.oop.Demo08;
public interface TimeService {
void run();
}
==========================================================
package com.oop.Demo08;
// abstract class :extents
// class Interface can be implemented implement Interface
// The class that implements the interface You need to rewrite the methods in the interface
// Multiple inheritance Using interfaces to implement multiple inheritance
public class UserServiceImpl implements UserService,TimeService{
@Override
public void add(String name) {
}
@Override
public void delete(String name) {
}
@Override
public void update(String name) {
}
@Override
public void query(String name) {
}
@Override
public void run() {
}
}
边栏推荐
- 【无标题】8 简易版通讯录
- Journal quotidien des questions (11)
- 【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
- Request weather interface format, automation
- 【code】if (list != null && list.size() > 0)优化,集合判空实现方式
- [Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
- Understand software testing
- 如何迁移或复制VMware虚拟机系统
- Reinstalling the system displays "setup is applying system settings" stationary
- [untitled] 5 self use history
猜你喜欢
The dynamic analysis and calculation of expressions are really delicious for flee
Selenium ide installation recording and local project maintenance
These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
Journal quotidien des questions (11)
Golang operation redis: write and read hash type data
论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
SQL实现将多行记录合并成一行
(翻译)异步编程:Async/Await在ASP.NET中的介绍
【类和对象】深入浅出类和对象
随机推荐
Print time Hahahahahaha
SQL实现将多行记录合并成一行
论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》
Yolov1 learning notes
Example of joint use of ros+pytoch (semantic segmentation)
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
Cannot get value with @value, null
认识弹性盒子flex
Local rviz call and display of remote rostopic
The list of "I'm crazy about open source" was released in the first week, with 160 developers on the list
2022 cisp-pte (III) command execution
致即将毕业大学生的一封信
Operation principle of lua on C: Foundation
Unit test framework + Test Suite
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
Realize PDF to picture conversion with C #
SSH link remote server and local display of remote graphical interface
如何迁移或复制VMware虚拟机系统
Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
How matlab modifies default settings