Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Programe para uma interface, não para uma implementação
Lightning talk apresentada na Python Brasil 12
Diego Garcia
October 17, 2016
More Decks by Diego Garcia
See All by Diego Garcia
Um overview sobre GIT
drgarcia1986
0
50
Modelos de concorrência e paralelismo em Python
drgarcia1986
0
110
Modelos de concorrência em Python.
drgarcia1986
0
190
Bot do Telegram
drgarcia1986
1
230
Boas práticas em REST APIs
drgarcia1986
1
1.4k
Conteinerizando aplicações Python
drgarcia1986
0
460
Testes de carga com Locust
drgarcia1986
1
460
Other Decks in Programming
See All in Programming
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
360
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
830
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
140
C# and C++ Interoperability - cho-dotnetnew
harukasao
0
260
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
540
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
250
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
790
さぁV100、メモリをお食べ・・・
nilpe
0
140
Creating Composable Callables in Contemporary C++
rollbear
0
150
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
240
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
160
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Context Engineering - Making Every Token Count
addyosmani
9
970
Fireside Chat
paigeccino
42
4k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
390
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
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