{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f795f928",
   "metadata": {},
   "source": [
    "# 14-13 · Skład\n",
    "\n",
    "Praktyka do sekcji [„Kompozycja: obiekty wewnątrz obiektów”](/pl/chapters/rozdzial-14/14-13-kompozitsiya.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0dc56e27",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Jeden obiekt przechowuje inny obiekt (HAS-A) i deleguje mu pracę."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "166c732b",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15510e9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Motor:\n",
    "    def __init__(self, moshchnost):\n",
    "        self.moshchnost = moshchnost\n",
    "\n",
    "    def start(self):\n",
    "        return f\"Двигатель мощностью {self.moshchnost} л.с. запущен\"\n",
    "\n",
    "\n",
    "class Avtomobil:\n",
    "    def __init__(self, moshchnost):\n",
    "        self.dvigatel = Motor(moshchnost)\n",
    "\n",
    "    def start(self):\n",
    "        return self.dvigatel.start()\n",
    "\n",
    "mashina = Avtomobil(150)\n",
    "print(mashina.start())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc2c921a",
   "metadata": {},
   "source": [
    "## Zadanie niezależne od zadania ★★\n",
    "\n",
    "Dodaj `Avtomobil` metoda `opisanie()`, który zwraca łańcuch znaków mocy silnika poprzez dostęp do `self.dvigatel.moshchnost`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4130c598",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Motor:\n",
    "    def __init__(self, moshchnost):\n",
    "        self.moshchnost = moshchnost\n",
    "\n",
    "    def start(self):\n",
    "        return f\"Двигатель мощностью {self.moshchnost} л.с. запущен\"\n",
    "\n",
    "\n",
    "class Avtomobil:\n",
    "    def __init__(self, moshchnost):\n",
    "        self.dvigatel = Motor(moshchnost)\n",
    "\n",
    "    def start(self):\n",
    "        return self.dvigatel.start()\n",
    "\n",
    "    def opisanie(self):\n",
    "        return f\"Автомобиль с двигателем {self.dvigatel.moshchnost} л.с.\"\n",
    "\n",
    "mashina = Avtomobil(150)\n",
    "print(mashina.opisanie())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "name": "python",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
