How to choose design pattern -


i learning design pattern , have question.

example, here first design.
shape
shape->red circle
shape->blue circle
shape->red square
shape->blue square
...

second design
shape
shape->circle
shape->square
shape->circle->red circle
shape->circle->blue circle
shape->square->red square
shape->square->bluesquare
...

thanks tony, come situation. in first design, shape class abstract, , have function "red square" , "blue square" only. means cannot define function in shape class need 1 one in "red square" , "blue square". same situation second design, can put new function in "square" class.
now, question correct , there other design can use?

your question not specific enough give solid answer. after discussing in comments clear actively trying learn design patterns may not clear best way ask question. providing answer have room type.

resources

dofactory - use reference source when looking pattern matches need.

head first design patterns - used book introduction design patterns , how use them. learning design patterns pivotal point understanding development. shows how use interfaces , abstractions achieve common problems in software development.

beginner guide design patterns - nice article started design patterns.

javascript design patterns - (bonus) site incredible learning javascript design patterns. including illustrate point make below looking design patterns language use.

when looking @ dofactory can see there 3 areas patterns fall into; creational, structural, behavioral. when looking pattern know trying achieve.

few tips

  • don't force pattern if not naturally fit problem.
  • don't on engineer solution trying force patterns every line of code write, useful not needed.
  • do use multiple patterns when necessary, 'ok' have multiple patterns playing close together, again.. if natural fit.
  • do learn few common patterns, small list own google search reveal others personal list of commonly used patterns;
    • strategy
    • [abstract] factory
    • singleton
    • command
    • decorator
    • observer
  • do design patterns language attempt learn, give better understanding how better utilize language. (see bonus link above)
  • do spread wings after decent understanding of gof patterns , enterprise design patterns.

i hope answer helps guide on path learning design patterns. know not answer question understand little better , enable return more specific question design patterns , usage code.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -