PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Nov 29, 2014 1:01 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Mon May 28, 2012 5:21 pm 
Offline
Forum Contributor

Joined: Sat Nov 19, 2011 10:32 am
Posts: 194
I have finally taken the quantum leap from procedural to to OOP.

1) i am reading books on OOP
2 ) reading codes designed in OOP

Atleast they have started making some sense to me now, though not yet coded anything n OOP so far

Next, design patterns (the gang of four book) is something i have been influenced to explore.
I read a little on the web but could not make much sense of its practical usage.

My Question

1) Where does 'design patterns' fit in the entire OOP schema ?>

Are they necessary to know ?


Top
 Profile  
 
PostPosted: Mon May 28, 2012 10:30 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 12697
Location: New York, NY, US
Live24x7 wrote:
1) Where does 'design patterns' fit in the entire OOP schema ?
They are simply Best Practice solutions to common problems. They are usually stated as a problem then a solution. They have been proven by the best and brightest over the years to be a successful way to solve these problems. Though the pattern concept is not OOP specific they are very much associated with OOP and are mostly OOP solutions.
Live24x7 wrote:
Are they necessary to know ?
Yes, because they provide a common language to talk about software problems/solutions without needing very long-winded explanations. They form a ubiquitous language to talk about these complex subjects.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon May 28, 2012 11:44 pm 
Offline
Forum Contributor

Joined: Sat Nov 19, 2011 10:32 am
Posts: 194
Thanks a lot :)

I read yesterday that design patterns are to programming what scales are to music :)


Top
 Profile  
 
PostPosted: Tue May 29, 2012 1:43 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 5663
Location: WA, USA
Live24x7 wrote:
I read yesterday that design patterns are to programming what scales are to music :)

Actually I'd say they're more like chords.

Scales are programming languages. They include a fairly definitive set of notes you can play, and playing different notes probably means you're doing something wrong. Occasionally you might use a couple different keys/scales in a single piece of music, but for the most part you're dealing with just one.
Chords are design patterns. They're a step above the fundamental building blocks of music and together form most of what you're writing. Some chords are easy to learn and play while other chords require a bit more background knowledge to understand and effort to master. But even without a proper musical education, if you've written enough music then you've probably used a few chords without even knowing it.


Top
 Profile  
 
PostPosted: Tue May 29, 2012 11:33 am 
Offline
Forum Contributor

Joined: Sat Nov 19, 2011 10:32 am
Posts: 194
wow ..that makes it even clear :)


Top
 Profile  
 
PostPosted: Tue May 29, 2012 2:24 pm 
Offline
Forum Newbie

Joined: Sat Mar 03, 2012 6:43 am
Posts: 19
Design patterns are great for solving common problems and to have a common ground deciding a solution with others. Of course we shouldn’t learn those and think them as golden rules, almost each programming real life problem is not as simple and distinctive as the problems design patterns solves. More over if you have in your mind a premade solution there is the danger to modify the problem fitting your solution making the all design really mess. Don’t get me wrong, design patterns have their place in our knowledge, but after knowing as many of them, test and use them where each fit , you can consider them as your programming experience and not holly grails.


Top
 Profile  
 
PostPosted: Tue May 29, 2012 2:29 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3805
Location: Montreal, Canada
kon wrote:
Design patterns are great for solving common problems and to have a common ground deciding a solution with others. Of course we shouldn’t learn those and think them as golden rules, almost each programming real life problem is not as simple and distinctive as the problems design patterns solves. More over if you have in your mind a premade solution there is the danger to modify the problem fitting your solution making the all design really mess. Don’t get me wrong, design patterns have their place in our knowledge, but after knowing as many of them, test and use them where each fit , you can consider them as your programming experience and not holly grails.

This is good advice. Beware the golden hammer.

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
PostPosted: Mon Jun 04, 2012 2:16 am 
Offline
Forum Contributor

Joined: Sat Nov 19, 2011 10:32 am
Posts: 194
@kon - thanks - very nicely explained.
That means - this is not something compulsory for a coder to know.
Infact knowing them may stifle creativity and the ability to search for original solutions.

@celaurun -
i had never heard of the term 'golden hammer'
read about it and couldn't have agreed more - if all you have is a hammer, everything looks like a nail


Top
 Profile  
 
PostPosted: Mon Jun 04, 2012 3:56 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 12697
Location: New York, NY, US
kon wrote:
if you have in your mind a premade solution there is the danger to modify the problem fitting your solution making the all design really mess

I think this is really poor advice and perhaps a misunderstanding of patterns. They are not pre-made solutions. No wonder you worry about golden hammers if you think of them as such. The danger of implementing the completely common poor design is much greater than the hypothetical condition of patterns somehow harming the design.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Jun 04, 2012 4:55 pm 
Offline
Forum Newbie

Joined: Sat Mar 03, 2012 6:43 am
Posts: 19
Christopher I would really like to learn your opinion about it, maybe I will learn something new (and I am not kiting). I agree with your first post and with Wikipedia ( http://en.wikipedia.org/wiki/Design_pattern ) . I am not advice anyone not to learn design patterns, the opposite. We should know them and use them a lot in experiment projects and learn their place in real life programming. For example I believe that we all have seen “Singleton” overused and not in right context. Why they do that? I believe simple because they had a “solution” , they modify the problem to fit the solution. So in that way it is a golden hammer (thank you celaurun for making me read more about the term). One more good link about design patterns is http://gee.cs.oswego.edu/dl/ca/ca/ca.html .


Top
 Profile  
 
PostPosted: Mon Jun 04, 2012 7:03 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 12697
Location: New York, NY, US
I don't think what you are describing is a golden hammer. What you are describing is the saying "when all you have is a hammer -- everything looks like a nail." You give a good example with the Singleton. Programmers usually start out by using a lot of global variables. It is the obvious solution, just not a good practice. So when they come to OOP they look for a design that will work just like their previous bad design. Hence the Singleton is misused. That is not the fault of the Singleton. The confusion is between thinking you want one instance of a variable (which is not the Singleton) and when you want only one instance of a class (which is a Singleton). The latter concept implies a solid understanding of classes that people new to OOP don't have. And if they did even a little reading about the Singleton pattern they would learn that it is not something you should use very often. There are warnings on most descriptions. They might even learn what an anti-pattern is!

I just think it doesn't make much sense to say, "People sometimes don't understand the best solutions to common problems, therefore they should keep using bad solutions." Design patterns are simply best practice solutions to design problems. They are misused because software design is difficult, not because patterns are somehow bad or a problem.

I would recommend that Live24x7 read about every pattern she/he can find. I recommend reading the GoF patterns first (search for them, here are a couple inks http://www.softpatterns.com/ or http://www.fluffycat.com/PHP-Design-Patterns/). Then would read Fowlers EAA patterns (http://martinfowler.com/eaaCatalog/). It takes years to understand when and how to apply them -- so you might as well start now. Design is very counter-intuitive so you need to slowly unlearn all the things you figured out on your own.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Wed Jun 27, 2012 4:43 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto
Others have covered this topic well, so I won't regurgitate anything. Just want to say design patterns are not a concept universally you can apply to fix bad design. It is just as important to know when to use them as it is to know what they are.

As you learn more about them, you may even find you have solved problems with design patterns without even knowing it, because it made sense, and likely simplified your design.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group