-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.13 - Implementação, decisões e assert
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Nesta implementação em Java, o livro utiliza o artificio 'static' da linguagem. | ||
Entretanto não há uma forma, em Python, para simular o comportamento de | ||
atributos estáticos EXATAMENTE como ocorre em Java. | ||
Para simular o comportamento em Python, o atributo estático deve ser acessado | ||
diretamente por sua classe, e não pela instância (como é feito no livro). | ||
""" | ||
|
||
|
||
class A: | ||
|
||
STATIC = int() | ||
|
||
def __init__(self): | ||
self.media = int() | ||
|
||
|
||
a = A() | ||
A.STATIC, a.STATIC, a.media = 5, 5, 5 | ||
|
||
b = A() | ||
A.STATIC, b.STATIC, b.media = 7, 7, 7 | ||
|
||
|
||
assert (A.STATIC, a.STATIC, a.media, b.STATIC, b.media) == (7, 5, 5, 7, 7) |