codeguy / php-the-right-way

An easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative tutorials around the Web
https://www.phptherightway.com
Other
9.04k stars 3.24k forks source link

More details about Design Patterns #370

Closed codeguy closed 6 years ago

codeguy commented 10 years ago

This issue is for discussion on a more detailed Design Patterns section. I think we should first decide which patterns to include, and then open up separate issues for each one for more in-depth discussion on each.

adambrett commented 10 years ago

I really like how http://sourcemaking.com/ covers this. I think they're trying to sell a book so I'm not sure how comfortable people would be linking to them directly but it's possibly a good start?.

n.b. I am not affiliated with them in any way at all.

codeguy commented 10 years ago

@adambrett Thanks. The goal here is to provide a basic definition and synopsis of each pattern with a simple example. We will provide links to external resources for more in-depth coverage.

codeguy commented 10 years ago

This is a list straight from Wikipedia referenced from the Gang of Four book. The goal is to cover each of these with a definition/synopsis and a brief example. We can provide outbound links for each pattern to more in-depth tutorials and articles.

http://en.wikipedia.org/wiki/Design_Patterns

The goal here is to provide a description, simple example, and a list of external references for each design pattern. A visitor should walk away from PHP The Right Way with a good understanding of a design pattern with a list of more in-depth external references to explore later.

If you want to claim a pattern, open a separate issue titled "[X] Pattern" and link to that issue in this thread. Each Design Pattern should have it's own stand-alone child page that lives in the pages/ subdirectory. We will link to this page from the front page.

Creational

Creational patterns are ones that create objects for you, rather than having you instantiate objects directly. This gives your program more flexibility in deciding which objects need to be created for a given case.

Structural

These concern class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.

Behavioral

Most of these design patterns are specifically concerned with communication between objects.

brandonsavage commented 10 years ago

I wrote a book on this recently. In my experience, you can drop Flyweight, Interpreter, Memento, and I would add MVC and Domain Modeling, as well as Active Record.

jeremykendall commented 10 years ago

/me raises my hand to contribute to Decorator. I'm a big fan of the Decorator pattern. I got this: #372.

codeguy commented 10 years ago

ALL: If you want to claim a given pattern, open a separate issue titled "[X] Pattern" and link to that issue in this thread.

philipobenito commented 10 years ago

@codeguy I'd love to get involved with this as the books we pull patterns from are not always helpful for beginners.

It is a massive undertaking though. I will keep an eye on this thread and if you want a chat about anything just shoot me a DM or an email.

codeguy commented 10 years ago

Further clarification. Each Design Pattern should have it's own stand-alone child page that lives in the pages/ subdirectory. We will link to this page from the front page.

philipobenito commented 10 years ago

I will take Chain of Command if nobody has any objections - Issue #373

codeguy commented 10 years ago

NOTE: The goal here is to provide a description, simple example, and a list of external references for each design pattern. A visitor should walk away from PHP The Right Way with a good understanding of a design pattern with a list of more in-depth external references to explore later.

davidstanley01 commented 10 years ago

I'll take Singleton.

ahmednaguib commented 10 years ago

I want to take factory method

codeguy commented 10 years ago

I'll take Observer.

jeremykendall commented 10 years ago

@codeguy Observer is a fun one, and brings back good memories.

brandonsavage commented 10 years ago

I'll take Facade, Bridge and Adapter. They're actually all related.

codeguy commented 10 years ago

@brandonsavage Thanks! Re: your earlier comment, I prefer to keep all of the patterns even if we just provide a very simple description and a note that they are not used often. I'm fine adding MVC, Domain Modeling, and Active Record :+1:

brandonsavage commented 10 years ago

You won't get any argument from me, that's for sure!

philsturgeon commented 10 years ago

Onxe everyone is done with their sections we'll have a 30 minute break then pass the issues one to the right. 

We'll all mark somebody else's answers and the winner gets a bottle of wine.

Josh is paying. — Sent from Mailbox for iPhone

On Thu, Mar 6, 2014 at 9:12 PM, brandonsavage notifications@github.com wrote:

You won't get any argument from me, that's for sure!

Reply to this email directly or view it on GitHub: https://github.com/codeguy/php-the-right-way/issues/370#issuecomment-36961411

codeguy commented 10 years ago

2 buck chuck it is.

philsturgeon commented 10 years ago

Its 3 buck in New York. The extortion! But yeah, happy writing folks. 

@brandonsavage make issues for your patterns so people know what's up. — Sent from Mailbox for iPhone

On Thu, Mar 6, 2014 at 9:21 PM, Josh Lockhart notifications@github.com wrote:

2 buck chuck it is.

Reply to this email directly or view it on GitHub: https://github.com/codeguy/php-the-right-way/issues/370#issuecomment-36961834

brandonsavage commented 10 years ago

@philsturgeon I filed #377.

On Thu, Mar 6, 2014 at 9:22 PM, Phil Sturgeon notifications@github.comwrote:

Its 3 buck in New York. The extortion! But yeah, happy writing folks.

@brandonsavage make issues for your patterns so people know what's up.

Sent from Mailbox for iPhone

On Thu, Mar 6, 2014 at 9:21 PM, Josh Lockhart notifications@github.com wrote:

2 buck chuck it is.

Reply to this email directly or view it on GitHub:

https://github.com/codeguy/php-the-right-way/issues/370#issuecomment-36961834

Reply to this email directly or view it on GitHubhttps://github.com/codeguy/php-the-right-way/issues/370#issuecomment-36961895 .

philsturgeon commented 10 years ago

Sweet. Missed that. Keep on trucking.— Sent from Mailbox for iPhone

On Thu, Mar 6, 2014 at 9:26 PM, brandonsavage notifications@github.com wrote:

@philsturgeon I filed #377. On Thu, Mar 6, 2014 at 9:22 PM, Phil Sturgeon notifications@github.comwrote:

Its 3 buck in New York. The extortion! But yeah, happy writing folks.

@brandonsavage make issues for your patterns so people know what's up.

Sent from Mailbox for iPhone

On Thu, Mar 6, 2014 at 9:21 PM, Josh Lockhart notifications@github.com wrote:

2 buck chuck it is.

Reply to this email directly or view it on GitHub:

https://github.com/codeguy/php-the-right-way/issues/370#issuecomment-36961834

Reply to this email directly or view it on GitHubhttps://github.com/codeguy/php-the-right-way/issues/370#issuecomment-36961895 .


Reply to this email directly or view it on GitHub: https://github.com/codeguy/php-the-right-way/issues/370#issuecomment-36962090

stormpat commented 10 years ago

For starters check out this repo: https://github.com/domnikl/DesignPatternsPHP it has many patterns covered.

stefanotorresi commented 10 years ago

i could take proxy

codeguy commented 10 years ago

@stormpat That has good examples, but little to no description which is what we will be doing here. That would be a good resource to link to though.

stefanotorresi commented 10 years ago

@codeguy what about object persistence patterns? Data Mapper and Active Record are surely worth a mention

philsturgeon commented 9 years ago

Where did we get to with this? I don't remember seeing much in the way of actual results, even though lots of people claimed various patterns. :)

JeroenDeDauw commented 9 years ago

I'm saddened to see the Singleton pattern being included, and even more so by it being the second one on the page.

At least there is this "You should be wary when using the singleton pattern" warning at the end. Though I wonder how many of the people reading this for the first time will actually see that. They probably read the intro, check the code, and implement it.

I'd just kill the Singleton pattern, though making the warning more prominent is already a good first step.

jrfnl commented 9 years ago

@JeroenDeDauw The singleton pattern has a place in oo in certain use cases, killing it would be the wrong way to go IMHO.

spiritix commented 8 years ago

IMHO only patterns should be included which require special implementation in PHP. Everything else is not related to a specific programming language like PHP.

codeguy commented 6 years ago

Closing. Linking to https://designpatternsphp.readthedocs.io/ now.