Lighthughjiajin's recent timeline updates
Lighthughjiajin

Lighthughjiajin

V2EX member #529934, joined on 2021-01-22 13:47:37 +08:00
群辉 + openwrz + zerotier ping 不通
互联网  •  Lighthughjiajin  •  Feb 26, 2023  •  Lastly replied by yaott2020
4
小白求推荐 P2 P 异地组网方案
互联网  •  Lighthughjiajin  •  May 22, 2023  •  Lastly replied by MoonDazeCry
5
关于在 Windows 终端执行 Python 文件
程序员  •  Lighthughjiajin  •  Oct 19, 2022  •  Lastly replied by elementp
15
关于 smaba 和 nfs 的区别?
程序员  •  Lighthughjiajin  •  Apr 26, 2022  •  Lastly replied by zjsxwc
17
求问,非科班程序员如何提高?
程序员  •  Lighthughjiajin  •  Apr 8, 2022  •  Lastly replied by bigmao0720
24
关于 openvpn server.conf 的配置问题
程序员  •  Lighthughjiajin  •  Apr 1, 2022  •  Lastly replied by allenforrest
22
自定义 Socket 接收 HTTP 请求,丢失请求体
Python  •  Lighthughjiajin  •  Nov 1, 2021  •  Lastly replied by julyclyde
10
Lighthughjiajin's recent replies
Jan 4, 2024
Replied to a topic by yinlei212 Python [困惑] 写好的 Python 应用如何分发?
pyinstaller 能保护源码吗?
Sep 15, 2023
Replied to a topic by feifeideyu Linux 自用电脑如何搭建 Linux 系统进行开发?
怎么不 docker
我写的是组合多个结构体来满足函数的 Device 接口参数要求,我看你写的是组合多个结构体来调用 sync ,也就是最终都是同一个类型,就是一个结构体。
@Contextualist 感谢大佬,我整理了一下。
https://go.dev/play/p/Z5Hl57w5XdF
看看我理解的对吗?
@Contextualist 这个写法下,有个缺点,Router 无法重写 Device 的 sync 方法,类似于以下 Python 代码
```
from abc import ABC, abstractmethod


class Device(ABC):

@abstractmethod
def fn(self):
raise NotImplementedError

def sync(self):
print("Start Sync ...")
self.fn()
print("Start Done.")


class PC(Device):

def fn(self):
print("PC sync")


class Router(Device):

def fn(self):
print("Router Device sync")

def sync(self):
print("Router 重写了 sync")
super().sync()
print("Router sync ...")


def start_sync(d: Device):
d.sync()


if __name__ == '__main__':
r = Router()
start_sync(r) # Run r.fn()
start_sync(PC())

```
@Contextualist 终于看到比较地道的写法,是我想了解的。
还有一点疑问,在这场景下,IDevice, Device 结构体、接口的命名有什么约定吗?
希望有机会看看这本书
Feb 25, 2023
Replied to a topic by Lighthughjiajin 互联网 群辉 + openwrz + zerotier ping 不通
我理解是,我本机访问一个不是同网段的地址,应该会问网关,但是默认网关是主路由。并不会走到 openwrz 。我回家看看我的主路由器支不支持给我配
SO 文件是别人提供的,不是我自己写的 。
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   799 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 24ms · UTC 19:32 · PVG 03:32 · LAX 12:32 · JFK 15:32
♥ Do have faith in what you're doing.