====== Доменные объекты ====== ===== Что такое доменные объекты ===== **Доменные объекты** - классы, представляющие какие-либо понятия той или иной предметной области. Примеры доменных доменных объектов: заказ, элемент каталога, посетитель, доставка, упаковка и т.д. Объекты, которые находятся под управлением подсистемы ORM Limb, должны реализовывать интерфейс **lmbPersistable**: interface lmbPersistable { function getId(); function setId($id); function getHash(); } Доменные объекты наследуют от **lmbPersistentObject**, который реализует это интерфейс. Наследование от этого класса гарантирует правильность работы транзакции с данными доменными объектами, а также дает пользоваться интерфейсом **Dataspace**, так lmbPersistentObject наследует от класса **lmbObject**. ===== Пример доменного доменного класса ===== Рассмотрим небольшой пример доменного объекта. Путь это будет класса Recipe (рецепт). У рецепта есть несколько аттрибутов: $title (заголовок), $recipe_items ингредиенты, $dish (посуда). Код данного класса будет таким: require_once(LPKG_CORE_DIR . '/core/orm/lmbPersistentObject.class.php'); require_once(LPKG_CORE_DIR . '/core/orm/lmbObjectCollection.class.php'); require_once(dirname(__FILE__) . '/RecipeItem.class.php'); class Recipe extends lmbPersistentObject { var $dish; var $recipe_items; function Recipe () { parent :: lmbPersistentObject(); $this->recipe_items = new lmbObjectCollection(); } function addIngredient($ingr, $amount, $time, $priority = 0) { $recipe_item = new RecipeItem(); $recipe_item->setIngredient($ingr); $recipe_item->setAmount($amount); $recipe_item->setTime($time); $recipe_item->setPriority($priority); $recipe_item->setRecipe($this); $this->recipe_items->add($recipe_item); } function removeIngredient($ingr) { foreach($this->recipe_items as $recipe_item) { if($recipe_item->getIngredient()->getId() == $ingr->getId()) { $this->recipe->remove($recipe_item); return; } } } function getRecipeItems() { return $this->recipe_items; } function setRecipeItems($items) { $this->recipe_items = $items; } function getTitle() { return $this->get('title'); } function setTitle($title) { $this->set('title', $title); } function getDish() { return $this->dish; } function setDish($dish) { $this->dish = $dish; } }