'Bringing back python classes;'
This commit is contained in:
parent
6624cc620d
commit
c6536762d1
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>wmii-prog-obiektowe-python</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.python.pydev.PyDevBuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.python.pydev.pythonNature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
@ -1,11 +0,0 @@
|
|||||||
from Figure import Figure
|
|
||||||
|
|
||||||
|
|
||||||
class Circle(Figure):
|
|
||||||
_r = None
|
|
||||||
|
|
||||||
def setr(self, r):
|
|
||||||
self._r = r
|
|
||||||
|
|
||||||
def area(self):
|
|
||||||
print("area = " + str(3.14 * self._r**2))
|
|
@ -1,4 +0,0 @@
|
|||||||
class Figure:
|
|
||||||
|
|
||||||
def area(self):
|
|
||||||
print("Not implemented")
|
|
@ -1,13 +0,0 @@
|
|||||||
from Figure import Figure
|
|
||||||
from Square import Square
|
|
||||||
|
|
||||||
|
|
||||||
class Rectangle(Square):
|
|
||||||
|
|
||||||
_y = None
|
|
||||||
|
|
||||||
def sety(self, y):
|
|
||||||
self._y = y
|
|
||||||
|
|
||||||
def area(self):
|
|
||||||
print("area = " + str(self._x * self._y))
|
|
@ -1,12 +0,0 @@
|
|||||||
from Figure import Figure
|
|
||||||
|
|
||||||
|
|
||||||
class Square(Figure):
|
|
||||||
|
|
||||||
_x = None
|
|
||||||
|
|
||||||
def setx(self, x):
|
|
||||||
self._x = x
|
|
||||||
|
|
||||||
def area(self):
|
|
||||||
print("area = " + str(self._x * self._x))
|
|
@ -1,15 +0,0 @@
|
|||||||
from Circle import Circle
|
|
||||||
from Figure import Figure
|
|
||||||
from Rectangle import Rectangle
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
r = Rectangle()
|
|
||||||
r.setx(4)
|
|
||||||
r.sety(8)
|
|
||||||
r.area()
|
|
||||||
|
|
||||||
c = Circle()
|
|
||||||
c.setr(1)
|
|
||||||
c.area()
|
|
||||||
|
|
||||||
print('Finished')
|
|
@ -20,14 +20,4 @@ if __name__ == '__main__':
|
|||||||
# print(str(s1.__name)) # will not work
|
# print(str(s1.__name)) # will not work
|
||||||
print(s1.get_name())
|
print(s1.get_name())
|
||||||
|
|
||||||
# generics... actually are not needed - duck typing
|
|
||||||
figList = [Figure('f1'), Figure('f2')]
|
|
||||||
print(figList)
|
|
||||||
print(*figList) # uses our __str__ function
|
|
||||||
|
|
||||||
figList = [Square('s1'), Square('s2')]
|
|
||||||
print(figList)
|
|
||||||
print(*figList) # uses our __str__ function
|
|
||||||
print(figList[0].get_name()) # but there is no help from IDE
|
|
||||||
|
|
||||||
print('Finished!')
|
print('Finished!')
|
Loading…
Reference in New Issue
Block a user