当前位置:网站首页>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() {
}
}
边栏推荐
- Golang operation redis: write and read hash type data
- 数值法求解最优控制问题(一)——梯度法
- 2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
- [open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
- Request weather interface format, automation
- 【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
- Scroll view specifies the starting position of the scrolling element
- 如何迁移或复制VMware虚拟机系统
- Time format record
- 熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
猜你喜欢
随机推荐
Introduction to software engineering
Floating menu operation
opencv
Simple password lock
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
After the Chrome browser is updated, lodop printing cannot be called
SQL implementation merges multiple rows of records into one row
Error c2017: illegal escape sequence
Basic teaching of crawler code
Judge whether the date time exceeds 31 days
Use selenium to climb the annual box office of Yien
scroll-view指定滚动元素的起始位置
熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
远端rostopic的本地rviz调用及显示
【类和对象】深入浅出类和对象
【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
【5G NR】UE注册流程
JMeter performance automation test









