Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Programe para uma interface, não para uma imple...
Search
Diego Garcia
October 17, 2016
Programming
0
190
Programe para uma interface, não para uma implementação
Lightning talk apresentada na Python Brasil 12
Diego Garcia
October 17, 2016
Tweet
Share
More Decks by Diego Garcia
See All by Diego Garcia
Um overview sobre GIT
drgarcia1986
0
44
Modelos de concorrência e paralelismo em Python
drgarcia1986
0
110
Modelos de concorrência em Python.
drgarcia1986
0
180
Bot do Telegram
drgarcia1986
1
220
Boas práticas em REST APIs
drgarcia1986
1
1.4k
Conteinerizando aplicações Python
drgarcia1986
0
450
Testes de carga com Locust
drgarcia1986
1
450
Other Decks in Programming
See All in Programming
クラウドに依存しないS3を使った開発術
simesaba80
0
170
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
200
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
130
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
300
tparseでgo testの出力を見やすくする
utgwkk
2
290
AIコーディングエージェント(Manus)
kondai24
0
220
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.4k
AIエージェントの設計で注意するべきポイント6選
har1101
5
2.4k
ローカルLLMを⽤いてコード補完を⾏う VSCode拡張機能を作ってみた
nearme_tech
PRO
0
170
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
460
AtCoder Conference 2025
shindannin
0
610
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
900
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
0
190
More Than Pixels: Becoming A User Experience Designer
marktimemedia
2
260
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
70k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
17
Technical Leadership for Architectural Decision Making
baasie
0
180
Are puppies a ranking factor?
jonoalderson
0
2.4k
GraphQLとの向き合い方2022年版
quramy
50
14k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
The Invisible Side of Design
smashingmag
302
51k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
31
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Transcript
Programe para uma interface, não para uma implementação #pybr12
Quem sou eu?
• Desenvolvedor a ~8 anos. • Desenvolvedor web a ~5
anos. • Pythonista a ~3 anos. • Django, Tornado, Aiohttp, etc. • Vimmer (#vim <3). • Aspirante a Gopher (#Golang <3). • Backend developer at LuizaLabs. Diego Garcia
Programar para uma interface significa se importar com “o que
faz?” e não com o “como faz?”
Exemplo de interface
class Storage: def get(self, key): pass def set(self, key, value):
pass
Exemplo de uso da interface
class Reader: def __init__(self, storage): self.storage = storage def get_info(self):
return self.storage.get('info')
Exemplo de implementação concreta
from redis import StrictRedis class RedisStorage: def __init__(self): self.redis =
StrictRedis() def get(self, key): return self.redis.get(key) def set(self, key, value): self.redis.set(key, value)
• RedisStorage • MemcachedStorage • DatabaseStorage • FileStorage • FakeStorage
• ...
Exemplo de carregamento dinâmico
from importlib import import_module def get_storage_backend(path): module_name, class_name = path.rsplit('.',
1) module = import_module(module_name) backend_class = getattr(module, class_name) return backend_class() storage = get_storage_backend( 'storages.redis.RedisStorage' )
Quem se preocupa com isso? • Django (ORM, Cache, etc).
• Asyncio (EventLoop). • SqlAchemy (Connectors, Engines, etc). • ...
Programar para uma interface já me salvou em uma blackfriday!
Trocamos a API de cálculo de frete só virando uma chave.
Obrigado! Se tiverem perguntas me procurem :) Twitter: @drgarcia1986 |
Github: /drgarcia1986