尤川豪   ·  4年前
445 貼文  ·  275 留言

看到滿酷的 design pattern:用實作介面來表示「增減功能」的行為

https://docs.laravel-excel.com/3.1/exports/collection.html

這個 design pattern 很酷 第一次看到

用實作介面來表示「增減功能」的行為

範例:

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
use App\User;
use App\Order;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

class UserPaymentExport implements FromCollection, WithHeadings, WithColumnFormatting, ShouldAutoSize, WithStrictNullComparison
{
    //...
}

說來奇怪,OOP 的「介面」初衷應該不是這樣的?

應該是用來規範實作介面的那些類別、確保它們都有提供某些方法才對?

  分享   共 1,284 次點閱
按了喜歡:
共有 0 則留言
還沒有人留言。歡迎分享您的觀點、或是疑問。
您的留言
尤川豪
445 貼文  ·  275 留言

Devs.tw 是讓工程師寫筆記、網誌的平台。隨手紀錄、寫作,方便日後搜尋!

歡迎您一起加入寫作與分享的行列!

查看所有文章