This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Uma boa forma de entender orientação a objetos é pensar na responsabilidade única que sua classe deve ter. | |
**O que é responsabilidade única?** | |
O princípio de responsabilidade única diz que cada componente do seu sistema seja ele classe, método, módulo, etc deve conter a responsabilidade de apenas uma parte do seu sistema. | |
Classes são abstrações de responsabilidades do seu sistema. | |
**Mas o que isso quer dizer em termos práticos?** Imagine o seguinte caso: | |
Qual a responsabilidade única da classe file do python? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import unittest | |
from pprint import pprint | |
DEBUG = True | |
def greedy(g): | |
vertices = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from flask import Flask, request, render_template | |
app = Flask(__name__) | |
@app.route("/send", methods=["POST"]) | |
def send(): | |
return request.form["data"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# raw types are immutable variables | |
x = 1 | |
def change(x): | |
x = 2 | |
change(x) | |
assert x == 1 | |
# you can use the global statement, but it's not a good practice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Water(object): | |
def __init__(self): | |
self._wet = False | |
@property | |
def wet(self): | |
return self._wet | |
@wet.setter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WHITE = (255, 255, 255) | |
class Game(object): | |
SCREEN_SIZE = (800, 600) | |
def __init__(self): | |
pygame.init() | |
self.screen = pygame.display.set_mode(Game.SCREEN_SIZE) | |
self.screen.fill(WHITE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("[bffdcas] EditarPerfilModel reset password ", function() { | |
var alertModel; | |
beforeEach(angular.mock.module('perfil_usuario')); | |
beforeEach(angular.mock.module('mockhttp')); | |
beforeEach(function (){ | |
// mocka o alertModel | |
alertModel = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
# Apenas um exemplo de como fazemos | |
# jeito errado | |
with open('dados.json', 'w') as f: | |
f.write('{dados:' + json.dumps(['dados']) + '}') | |
# jeito certo | |
with open('dados.json', 'w') as f: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends '/gerenciar/base.html' %} | |
{% block js %} | |
<script type="text/javascript" src="/static/angular/js/angular.min.js"></script> | |
<script type="text/javascript" src="/static/jogos/jogo_form.js"></script> | |
<script type="text/javascript"> | |
var jogoApp = angular.module('jogoApp', ['jogoModulo']).controller("JogoController", function($scope){ | |
$scope.jogo={tit: 'Teste', map: 'Teste', qtd: '1', tmp: 'Sem limite', grp: 'Jogo Aberto'}; | |
$scope.mostra=false; | |
$scope.formOnOff=function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hp + potion | |
hp - dano | |
critico = dano ** 2 |