Java类中的 is-a、is-like-a、has-a

本文探讨了面向对象设计中的三种核心关系:聚合(has-a)、继承(is-a)与实现(is-like-a),并举例说明如何在软件设计中应用这些概念。
摘要由CSDN通过智能技术生成

转载:https://blog.csdn.net/qq2632246528/article/details/113619080

has a
关联关系:聚合
凡是能够使用 has a 来描述的,统一以属性的方式存在

例如 Customer has a FoodMenu(顾客有一个食物菜单)

is a
继承关系:继承
凡是满足is a的表达式都可以设置为继承

例如 Cat is a Animal(猫是一种动物)

is like a
实现关系:接口
满足 is like a 的表达式也是一种继承

实现关系通常是:类实现接口

但是在继承中,仅覆盖了父类方法即为Is-a;若在覆盖父类方法基础上有新增方法,则为Is-like-a。

例子:
1.假设你确定两件对象之间是is-a的关系,那么此时你应该使用继承。比方菱形、圆形和方形都是形状的一种。那么他们都应该从形状类继承。

2.假设你确定两件对象之间是has-a的关系,那么此时你应该使用聚合。比方电脑是由显示器、CPU、硬盘等组成的。那么你应该把显示器、CPU、硬盘这些类聚合成电脑类。

3.假设你确定两件对象之间是like-a的关系,那么此时你应该使用组合。比方空调继承于制冷机,但它同一时候有加热功能。那么你应该把让空调继承制冷机类,并实现加热接口

### Java Wechaty Library Documentation and Resources The official support for the Wechaty library is primarily targeted at Node.js, but there exists a community-driven port to other languages including Java. For developers interested in integrating WeChat functionality into their applications using Java, exploring third-party contributions becomes essential[^1]. To find relevant libraries or resources related specifically to **Java-Wechaty**, one can start by visiting GitHub repositories where enthusiasts might have contributed unofficial ports of this project. A direct link to such projects may not be available through official channels; therefore, searching within developer communities like Stack Overflow, Reddit’s r/programming, or even joining dedicated chat groups on platforms like Slack or Discord could prove beneficial. For those who prefer sticking with officially supported options while still working in a JVM environment, considering alternatives that offer similar functionalities would also make sense. One alternative approach involves utilizing the original JavaScript version via GraalVM's polyglot capabilities which allows running multiple language scripts together efficiently without needing separate processes[^2]. Additionally, staying updated about any new developments around Wechaty requires following its main repository as well as keeping an eye out for announcements from contributors regarding potential updates or forks supporting additional programming environments beyond what has been documented so far[^3]. ```java // Example Code Using Unofficial Port (Hypothetical Scenario) import io.github.wechaty.Wechaty; public class Main { public static void main(String[] args) throws Exception { Wechaty bot = new Wechaty(); bot.onMessage((message) -> System.out.println("Received message: " + message)); bot.start().thenRun(() -> System.out.println("Bot started!")); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值