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
100
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
450
Other Decks in Programming
See All in Programming
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
3
250
Laravel Boost 超入門
fire_arlo
3
220
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
2
1.3k
楽して成果を出すためのセルフリソース管理
clipnote
0
180
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
290
Improving my own Ruby thereafter
sisshiki1969
1
160
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
3
1.5k
個人軟體時代
ethanhuang13
0
330
Zendeskのチケットを Amazon Bedrockで 解析した
ryokosuge
3
320
Android端末で実現するオンデバイスLLM 2025
masayukisuda
1
170
はじめてのMaterial3 Expressive
ym223
2
890
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
BBQ
matthewcrist
89
9.8k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.1k
The Cost Of JavaScript in 2023
addyosmani
53
8.9k
Building Applications with DynamoDB
mza
96
6.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
A Tale of Four Properties
chriscoyier
160
23k
Embracing the Ebb and Flow
colly
87
4.8k
How to Think Like a Performance Engineer
csswizardry
26
1.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
Side Projects
sachag
455
43k
How STYLIGHT went responsive
nonsquared
100
5.8k
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