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
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
40
Modelos de concorrência e paralelismo em Python
drgarcia1986
0
97
Modelos de concorrência em Python.
drgarcia1986
0
180
Bot do Telegram
drgarcia1986
1
210
Boas práticas em REST APIs
drgarcia1986
1
1.4k
Conteinerizando aplicações Python
drgarcia1986
0
440
Testes de carga com Locust
drgarcia1986
1
440
Other Decks in Programming
See All in Programming
実践!App Intents対応
yuukiw00w
1
220
0から始めるモジュラーモノリス-クリーンなモノリスを目指して
sushi0120
0
250
自作OSでDOOMを動かしてみた
zakki0925224
1
1.2k
Android 15以上でPDFのテキスト検索を爆速開発!
tonionagauzzi
0
190
Amazon Q CLI開発で学んだAIコーディングツールの使い方
licux
3
180
Workers を定期実行する方法は一つじゃない
rokuosan
0
140
iOS開発スターターキットの作り方
akidon0000
0
240
Scale out your Claude Code ~自社専用Agentで10xする開発プロセス~
yukukotani
9
1.8k
なぜあなたのオブザーバビリティ導入は頓挫するのか
ryota_hnk
5
580
新しいモバイルアプリ勉強会(仮)について
uetyo
1
250
AIのメモリー
watany
13
1.4k
No Install CMS戦略 〜 5年先を見据えたフロントエンド開発を考える / no_install_cms
rdlabo
0
480
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Agile that works and the tools we love
rasmusluckow
329
21k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.3k
Raft: Consensus for Rubyists
vanstee
140
7.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
22
1.4k
Bash Introduction
62gerente
614
210k
Being A Developer After 40
akosma
90
590k
Statistics for Hackers
jakevdp
799
220k
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