-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
151 additions
and
1 deletion.
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
Binary file not shown.
Empty file.
Binary file added
BIN
+179 Bytes
examples/lab_python_oop/lab_python_oop/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+1.72 KB
examples/lab_python_oop/lab_python_oop/__pycache__/circle.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+865 Bytes
examples/lab_python_oop/lab_python_oop/__pycache__/color.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+740 Bytes
examples/lab_python_oop/lab_python_oop/__pycache__/figure.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+1.83 KB
examples/lab_python_oop/lab_python_oop/__pycache__/rectangle.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+1.3 KB
examples/lab_python_oop/lab_python_oop/__pycache__/square.cpython-36.pyc
Binary file not shown.
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,36 @@ | ||
from lab_python_oop.figure import Figure | ||
from lab_python_oop.color import FigureColor | ||
import math | ||
|
||
|
||
class Circle(Figure): | ||
""" | ||
Класс «Круг» наследуется от класса «Геометрическая фигура». | ||
""" | ||
FIGURE_TYPE = "Круг" | ||
|
||
@classmethod | ||
def get_figure_type(cls): | ||
return cls.FIGURE_TYPE | ||
|
||
def __init__(self, color_param, r_param): | ||
""" | ||
Класс должен содержать конструктор по параметрам «радиус» и «цвет». В конструкторе создается объект класса «Цвет фигуры» для хранения цвета. | ||
""" | ||
self.r = r_param | ||
self.fc = FigureColor() | ||
self.fc.colorproperty = color_param | ||
|
||
def square(self): | ||
""" | ||
Класс должен переопределять метод, вычисляющий площадь фигуры. | ||
""" | ||
return math.pi*(self.r**2) | ||
|
||
def __repr__(self): | ||
return '{} {} цвета радиусом {} площадью {}.'.format( | ||
Circle.get_figure_type(), | ||
self.fc.colorproperty, | ||
self.r, | ||
self.square() | ||
) |
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,22 @@ | ||
|
||
class FigureColor: | ||
""" | ||
Класс «Цвет фигуры» | ||
""" | ||
|
||
def __init__(self): | ||
self._color = None | ||
|
||
@property | ||
def colorproperty(self): | ||
""" | ||
Get-аксессор | ||
""" | ||
return self._color | ||
|
||
@colorproperty.setter | ||
def colorproperty(self, value): | ||
""" | ||
Set-аксессор | ||
""" | ||
self._color = value |
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,13 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Figure(ABC): | ||
""" | ||
Абстрактный класс «Геометрическая фигура» | ||
""" | ||
@abstractmethod | ||
def square(self): | ||
""" | ||
содержит виртуальный метод для вычисления площади фигуры. | ||
""" | ||
pass |
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,37 @@ | ||
from lab_python_oop.figure import Figure | ||
from lab_python_oop.color import FigureColor | ||
|
||
|
||
class Rectangle(Figure): | ||
""" | ||
Класс «Прямоугольник» наследуется от класса «Геометрическая фигура». | ||
""" | ||
FIGURE_TYPE = "Прямоугольник" | ||
|
||
@classmethod | ||
def get_figure_type(cls): | ||
return cls.FIGURE_TYPE | ||
|
||
def __init__(self, color_param, width_param, height_param): | ||
""" | ||
Класс должен содержать конструктор по параметрам «ширина», «высота» и «цвет». В конструкторе создается объект класса «Цвет фигуры» для хранения цвета. | ||
""" | ||
self.width = width_param | ||
self.height = height_param | ||
self.fc = FigureColor() | ||
self.fc.colorproperty = color_param | ||
|
||
def square(self): | ||
""" | ||
Класс должен переопределять метод, вычисляющий площадь фигуры. | ||
""" | ||
return self.width*self.height | ||
|
||
def __repr__(self): | ||
return '{} {} цвета шириной {} и высотой {} площадью {}.'.format( | ||
Rectangle.get_figure_type(), | ||
self.fc.colorproperty, | ||
self.width, | ||
self.height, | ||
self.square() | ||
) |
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,27 @@ | ||
from lab_python_oop.rectangle import Rectangle | ||
|
||
|
||
class Square(Rectangle): | ||
""" | ||
Класс «Квадрат» наследуется от класса «Прямоугольник». | ||
""" | ||
FIGURE_TYPE = "Квадрат" | ||
|
||
@classmethod | ||
def get_figure_type(cls): | ||
return cls.FIGURE_TYPE | ||
|
||
def __init__(self, color_param, side_param): | ||
""" | ||
Класс должен содержать конструктор по параметрам «сторона» и «цвет». | ||
""" | ||
self.side = side_param | ||
super().__init__(color_param, self.side, self.side) | ||
|
||
def __repr__(self): | ||
return '{} {} цвета со стороной {} площадью {}.'.format( | ||
Square.get_figure_type(), | ||
self.fc.colorproperty, | ||
self.side, | ||
self.square() | ||
) |
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,15 @@ | ||
from lab_python_oop.rectangle import Rectangle | ||
from lab_python_oop.circle import Circle | ||
from lab_python_oop.square import Square | ||
|
||
|
||
def main(): | ||
r = Rectangle("синего", 3, 2) | ||
c = Circle("зеленого", 5) | ||
s = Square("красного", 5) | ||
print(r) | ||
print(c) | ||
print(s) | ||
|
||
if __name__ == "__main__": | ||
main() |