Values 本文未发布 发布文章

未匹配的标注

Definition & Principles

Values are short names for the known “Value Objects” which are simple Objects, pretty similar to Models in the concept of representing data, but they do not get stored in the DB, thus they don’t have ID’s. They also do not hold functionality or change any state, they just hold data.
A Value Object is an immutable object that is defined by its encapsulated attributes. We create Value Object when we need it to represent/serve/manipulate some data (attached as attributes), and w’ll kill it later when we finish using it, to recreate it again when needed.

Rules

  • All Models MUST extend from App\Ship\Parents\Values\Value.

Folder Structure

 - App
    - Containers
        - {container-name}
            - Values
                - Output.php
                - Region.php
                - ...

Code Sample

<?php

use App\Ship\Parents\Values\Value;

class Location extends Value
{
    private $x = null;

    private $y = null;

    protected $resourceKey = 'locales';

    public function __construct($x, $y)
    {
        $this->x = $x;
        $this->y = $y;
    }

    public function getCoordinatesAsString()
    {
        return $this->x . ' - ' . $this->y;
    }
}

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
发起讨论 只看当前版本


暂无话题~