All Projects → OMGZui → Designpattern

OMGZui / Designpattern

Licence: mit
设计模式

Projects that are alternatives of or similar to Designpattern

generator-composer
🐘 Yeoman (http://yeoman.io) generator for a PHP Composer project
Stars: ✭ 16 (-75.76%)
Mutual labels:  composer, phpunit
php-mime-detector
Detect a file's mime type using magic numbers.
Stars: ✭ 20 (-69.7%)
Mutual labels:  composer, phpunit
laravel-survey
Laravel 6 survey app.
Stars: ✭ 39 (-40.91%)
Mutual labels:  composer, phpunit
design-pattern-examples-in-crystal
UML model and code examples of design patterns for Crystal. The model is created with Astah.
Stars: ✭ 51 (-22.73%)
Mutual labels:  uml, design-patterns
Design Patterns
Contains examples of design patterns that implemented in php
Stars: ✭ 375 (+468.18%)
Mutual labels:  design-patterns, phpunit
uml-diagram-for-kotlin-design-pattern-examples
UML diagram list of GoF design pattern examples written in Kotlin.
Stars: ✭ 23 (-65.15%)
Mutual labels:  uml, design-patterns
php-finder refactoring-kata
🐘🔍Incomprehensible Finder Refactoring Kata port for PHP
Stars: ✭ 22 (-66.67%)
Mutual labels:  composer, phpunit
Pdt
PHP Development Tools project (PDT)
Stars: ✭ 135 (+104.55%)
Mutual labels:  composer, phpunit
Examplesofdesignpatterns
设计模式的总结与例子(有XMind,Uml图和详细代码实现说明)
Stars: ✭ 265 (+301.52%)
Mutual labels:  design-patterns, uml
assert-true
A lot of ways to you set your assert as true
Stars: ✭ 19 (-71.21%)
Mutual labels:  composer, phpunit
design-pattern-examples-in-python
UML model and code examples of design patterns for Python. The model is created with Astah.
Stars: ✭ 27 (-59.09%)
Mutual labels:  uml, design-patterns
Phpqa
Docker image that provides static analysis tools for PHP
Stars: ✭ 853 (+1192.42%)
Mutual labels:  composer, phpunit
Designpatternsphp
sample code for several design patterns in PHP 8
Stars: ✭ 20,158 (+30442.42%)
Mutual labels:  design-patterns, phpunit
Uml Diagram For Python Design Pattern Examples
UML diagram list of GoF design pattern examples written in Python.
Stars: ✭ 40 (-39.39%)
Mutual labels:  design-patterns, uml
Vnote
A pleasant note-taking platform.
Stars: ✭ 8,714 (+13103.03%)
Mutual labels:  uml
Packagist Mirror
Alibaba Cloud Packagist Mirror
Stars: ✭ 63 (-4.55%)
Mutual labels:  composer
Spinupwp Composer Site
A WordPress site setup using Composer that is primed and ready to be hosted using SpinupWP.
Stars: ✭ 58 (-12.12%)
Mutual labels:  composer
Php frameworks analysis
php框架源码分析
Stars: ✭ 57 (-13.64%)
Mutual labels:  composer
Formula Parser
Parsing and evaluating mathematical formulas given as strings.
Stars: ✭ 62 (-6.06%)
Mutual labels:  composer
Pkgmirror
Packages Mirroring
Stars: ✭ 62 (-6.06%)
Mutual labels:  composer

DesignPattern 设计模式

零、使用

1、安装

composer create-project -s dev omgzui/design-pattern

or

git clone https://github.com/OMGZui/DesignPattern
composer install

2、测试

vendor/bin/phpunit tests/

一、什么是设计模式

设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时间的试验和错误总结出来的。

设计模式是一套被反复使用的、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了重用代码、让代码更容易被他人理解、保证代码可靠性。 毫无疑问,设计模式于己于他人于系统都是多赢的,设计模式使代码编制真正工程化,设计模式是软件工程的基石,如同大厦的一块块砖石一样。项目中合理地运用设计模式可以完美地解决很多问题,每种模式在现实中都有相应的原理来与之对应,每种模式都描述了一个在我们周围不断重复发生的问题,以及该问题的核心解决方案,这也是设计模式能被广泛应用的原因。

二、设计模式的类型

  • 创建型模式(Creational):这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式,而不是使用 new 运算符直接实例化对象。这使得程序在判断针对某个给定实例需要创建哪些对象时更加灵活
    • 简单工厂模式(Simple Factory Pattern) 传送门
    • 抽象方法模式(Factory Method Pattern) 传送门
    • 抽象工厂模式(Abstract Factory Pattern) 传送门
    • 单例模式(Singleton Pattern) 传送门
    • 建造者模式(Builder Pattern) 传送门
    • 原型模式(Prototype Pattern) PHP使用clone即可实现,目的是减少开销
  • 结构型模式(Structural):这些设计模式关注类和对象的组合。继承的概念被用来组合接口和定义组合对象获得新功能的方式
    • 适配器模式(Adapter Pattern) 传送门
    • 桥接模式(Bridge Pattern) 传送门
    • 装饰器模式(Decorator Pattern) 传送门
    • 外观模式(Facade Pattern) 传送门
    • 享元模式(Flyweight Pattern) 传送门
    • 代理模式(Proxy Pattern) 传送门
  • 行为型模式(Behavioral):这些设计模式特别关注对象之间的通信
    • 责任链模式(Chain of Responsibility Pattern) 传送门
    • 命令模式(Command Pattern) 传送门
    • 迭代器模式(Iterator Pattern) 传送门
    • 备忘录模式(Memento Pattern) 传送门
    • 观察者模式(Observer Pattern) 传送门
    • 状态模式(State Pattern) 传送门
    • 策略模式(Strategy Pattern) 传送门
    • 访问者模式(Visitor Pattern) 传送门
    • 模板方法模式(Template Method Pattern) 传送门

三、设计模式的六大原则

  • 开闭原则(Open Close Principle)

开闭原则的意思是:对扩展开放,对修改关闭。在程序需要进行拓展的时候,不能去修改原有的代码,实现一个热插拔的效果。简言之,是为了使程序的扩展性好,易于维护和升级。想要达到这样的效果,我们需要使用接口和抽象类,后面的具体设计中我们会提到这点。

  • 里氏代换原则(Liskov Substitution Principle)

里氏代换原则是面向对象设计的基本原则之一。 里氏代换原则中说,任何基类可以出现的地方,子类一定可以出现。LSP 是继承复用的基石,只有当派生类可以替换掉基类,且软件单位的功能不受到影响时,基类才能真正被复用,而派生类也能够在基类的基础上增加新的行为。里氏代换原则是对开闭原则的补充。实现开闭原则的关键步骤就是抽象化,而基类与子类的继承关系就是抽象化的具体实现,所以里氏代换原则是对实现抽象化的具体步骤的规范。

  • 依赖倒转原则(Dependence Inversion Principle)

这个原则是开闭原则的基础,具体内容:针对接口编程,依赖于抽象而不依赖于具体。

  • 接口隔离原则(Interface Segregation Principle)

这个原则的意思是:使用多个隔离的接口,比使用单个接口要好。它还有另外一个意思是:降低类之间的耦合度。由此可见,其实设计模式就是从大型软件架构出发、便于升级和维护的软件设计思想,它强调降低依赖,降低耦合

  • 迪米特法则,又称最少知道原则(Demeter Principle)

最少知道原则是指:一个实体应当尽量少地与其他实体之间发生相互作用,使得系统功能模块相对独立

  • 合成复用原则(Composite Reuse Principle)

合成复用原则是指:尽量使用合成/聚合的方式,而不是使用继承。

四、UML类图

UML类图

资料

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].