Tutti Nuovi

user:thomas utente che ha creato il gist

title:mygist titolo del gist

filename:myfile.txt nome di file nel gist

extension:yml estensione del file nel gist

language:go linguaggio del file nel gist

topic:homelab gists with given topic

Entra


Tutti Nuovi Entra

All gists matching topic abc-class

Più recente creazione
Meno recente creazione
Più recente aggiornamento
Meno recente aggiornamento

timmy / 簡單實作資料庫依賴注入

0 mi piace
0 forks
1 files
Ultima volta attivo 7 months ago
用 Python 實現資料庫介面,輕鬆切換不同資料庫實作。
abc-class database dependency-injection interface mysql oop python
1 from abc import ABC, abstractmethod
2
3 # 定義一個資料庫介面,規定大家都要有 connect 方法
4 class IDatabase(ABC):
5 @abstractmethod
6 def connect(self):
7 pass
8
9 # 具體實作 MySQL 版資料庫
10 class MySQLDatabase(IDatabase):
Più nuovi Più vecchi

Creato da Opengist ⋅ Load: 44ms⋅

Italiano
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文