承接 vasildakov/duck 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vasildakov/duck

最新稳定版本:v1.0.0

Composer 安装命令:

composer require vasildakov/duck

包简介

A PHP duck model demonstrating composition over inheritance.

README 文档

README

CI PHP Version Require Latest Stable Version License Coverage Status

Overview

Duck is a small educational PHP package that demonstrates the composition-over-inheritance design principle using a duck behavior model.

Instead of hardcoding behavior in class hierarchies, each duck is composed from interchangeable fly and quack strategies. This keeps behavior explicit, testable, and easy to extend.

Installation

composer require vasildakov/duck

Quick Example

<?php

declare(strict_types=1);

use CoI\Model\Duck\MallardDuck;
use CoI\Model\Duck\Fly\FlyWithWings;
use CoI\Model\Duck\Quack\Quack;

$duck = new MallardDuck(new FlyWithWings(), new Quack());

echo $duck->display() . PHP_EOL; // I'm a real Mallard duck
echo $duck->fly() . PHP_EOL;     // I'm flying!!
echo $duck->quack() . PHP_EOL;   // Quack

Why Composition Over Inheritance

  • behavior can be swapped without changing duck classes
  • behavior is separated into focused, reusable strategy classes
  • testing is simpler because each strategy is isolated
  • extending with new behaviors does not require deep inheritance trees

Background

"Composition over inheritance (or composite reuse principle) in object-oriented programming is the principle that classes should achieve polymorphic behavior and code reuse by their composition (by containing instances of other classes that implement the desired functionality) rather than inheritance from a base or parent class." Wikipedia

"If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck." The Duck test

"If it looks like a duck and quacks like a duck but it needs batteries, you probably have the wrong abstraction." Derick Bailey

License

This package is licensed under the MIT License. See LICENSE for details.

Author

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固