types - 给定一个类型,如何找到我需要实现的所有功能
问题描述
我正在阅读 Christopher Rackauckas 的优秀 Julia 博客Type-Dispatch Design: Post Object-Oriented Programming for Julia
在其中,他描述了“在面向对象的编程语言中,您如何按实现细节分组,在类型调度编程中,您如何按操作分组”。例如,在博客中有一个带有 AbstractPerson 的代码示例,它被描述为“一个人是有一个可以通过 get_name 获取的名字的人”。
所以,如果我正在使用一些使用某种类型的库,并且我想自己实现该类型,我如何列出我需要实现的所有功能?例如,如果我想创建自己的 Person 类型,我如何发现需要正确处理 get_name 函数?
Julia 是否会跟踪这些信息,如果是,我如何访问它?
解决方案
What you are looking for is typically called an interface. Currently, interfaces are only informal in Julia. They are usually specified in the documentation of a package or Julia itself. For example, see here the interface definition for AbstractArray
. Hence there is no built in function that lists all the mandatory methods that you must implement. However, interfaces might become first class in future Julia versions.
To answer your title question, you might want to take a look at methodswith(type)
. Note, though, that this won't give you all methods that can be called with an object of the given type
(take a look at the optional keyword argument supertypes::Bool
.
推荐阅读
- python - OpenCV 校准 Charuco 板cornerSubPix
- android - 如何在 react-native-alarm-notification 中设置重复警报,例如(星期一,星期二)
- javascript - React Native:如何将 reactjs 中的 loadscript 转换为 react native
- windows - 如何使用 pnputil 安装与 hwid 关联的驱动程序
- node.js - 构建具有特定节点版本的 docker ubuntu 机器
- azure - Powershell - Azure 存储帐户 - 获取上次身份验证时间/日期
- ssl - 让我们加密 SSL 更新问题
- python - Python 错误 - 基数为 10 的 int() 的文字无效:''
- c# - 该脚本不继承可以管理脚本的本机类。错误
- c# - 浏览器未使用的 Chrome 选项