Enterprise Cake

3,272
-1

Published on

Published in: Software

Enterprise Cake

  1. 1. EnterpriseCakeEnterpriseCake JamesWattsJamesWatts james.watts@cakephp.org
  2. 2. Cake Development Corporation whoamiwhoami / JamesWatts/ JamesWatts (@_JAMESWATTS_)(@_JAMESWATTS_) / InvolvedinOpenSourcesince2008/ InvolvedinOpenSourcesince2008 / Using PHPforthelast 10years/ Using PHPforthelast 10years / Corememberof CakePHP/ Corememberof CakePHP / Organizerof CakeFest/ Organizerof CakeFest / Teamleadat CakeDC/ Teamleadat CakeDC / Authorof XHTTP andDocMLspecs/ Authorof XHTTP andDocMLspecs / CakePHP2 ApplicationCookbook/ CakePHP2 ApplicationCookbook
  3. 3. Cake Development Corporation
  4. 4. Cake Development Corporation TheoryTheory
  5. 5. Cake Development Corporation WriteLessCodeWriteLessCode AndWriteFewerQueriesAndWriteFewerQueries
  6. 6. Cake Development Corporation Writinglesscodemeans...Writinglesscodemeans... > Reducinglegacytomaintain> Reducinglegacytomaintain > Introducingfeweredgecases> Introducingfeweredgecases > Lessopportunityforhumanerror> Lessopportunityforhumanerror > Fasterdevelopment efforts> Fasterdevelopment efforts > Lesscodetotest andcover> Lesscodetotest andcover > Enjoyment factorincreases!> Enjoyment factorincreases!
  7. 7. Cake Development Corporation CakePHPCakePHP PromotesPromotes LessCodeLessCode RapidApplicationDevelopmentRapidApplicationDevelopment
  8. 8. Cake Development Corporation ConventionOverConfigurationConventionOverConfiguration
  9. 9. Cake Development Corporation Don'tWorkAroundCakePHPDon'tWorkAroundCakePHP MakeFullUseOfFrameworkConventionsMakeFullUseOfFrameworkConventions
  10. 10. Cake Development Corporation Don'tReinventWheelsDon'tReinventWheels BeAwareOfTheBoredomFactor,AndTheDesireToHack!BeAwareOfTheBoredomFactor,AndTheDesireToHack!
  11. 11. Cake Development Corporation KeepItSimpleKeepItSimple CodeIsSimpleUntilCodeIsSimpleUntil YouYou MakeItComplicatedMakeItComplicated
  12. 12. Cake Development Corporation Don'tRepeatRepeatYourselfDon'tRepeatRepeatYourself TakeFullAdvantageOfComponents,BehaviorsAndHelpersTakeFullAdvantageOfComponents,BehaviorsAndHelpers
  13. 13. Cake Development Corporation DesignUp-FrontDesignUp-Front FollowYourBusinessObjectives,NotYourTechnicalSolutionFollowYourBusinessObjectives,NotYourTechnicalSolution
  14. 14. Cake Development Corporation TreatYourCodeAsProductTreatYourCodeAsProduct WriteProductionReadyCodeAsIfItWereForSomeoneElseWriteProductionReadyCodeAsIfItWereForSomeoneElse
  15. 15. Cake Development Corporation Command/QuerySeparationCommand/QuerySeparation SeparateactionsthatchangestatefromthosewhichconsultstateSeparateactionsthatchangestatefromthosewhichconsultstate
  16. 16. Cake Development Corporation BuildSOLIDCodeBuildSOLIDCode ApplyThe“FirstFive”DesignPrinciplesToYourCodeApplyThe“FirstFive”DesignPrinciplesToYourCode
  17. 17. Cake Development Corporation S.O.L.I.DS.O.L.I.D > SingleResponsibilityPrincipal> SingleResponsibilityPrincipal > Open/ClosedPrincipal> Open/ClosedPrincipal > LiskovSubstitutionPrinciple> LiskovSubstitutionPrinciple > InterfaceSegregationPrinciple> InterfaceSegregationPrinciple > DependencyInversionPrinciple> DependencyInversionPrinciple
  18. 18. Cake Development Corporation GetAGRASPOfYourCodeGetAGRASPOfYourCode General Responsibility AssignmentSoftwarePatternsGeneral Responsibility AssignmentSoftwarePatterns
  19. 19. Cake Development Corporation G.R.A.S.PG.R.A.S.P > ControllerPattern> ControllerPattern > CreatorPattern> CreatorPattern > HighCohesion> HighCohesion > Indirection Pattern> Indirection Pattern > ExpertPrincipal> ExpertPrincipal > LowCoupling> LowCoupling > Polymorphism> Polymorphism > ProtectedVariations> ProtectedVariations > PureFabrication> PureFabrication
  20. 20. Cake Development Corporation Don'tBeSTUPID!Don'tBeSTUPID! AvoidBadPracticesWhichWillWasteYourTimeLaterAvoidBadPracticesWhichWillWasteYourTimeLater
  21. 21. Cake Development Corporation S.T.U.P.I.DS.T.U.P.I.D > Singleton> Singleton > Tight Coupling> Tight Coupling > Untestability> Untestability > PrematureOptimization> PrematureOptimization > IndescriptiveNaming> IndescriptiveNaming > Duplication> Duplication
  22. 22. Cake Development Corporation KeepThingsInContextKeepThingsInContext TheLawOfDemeter,Don'tTalkToStrangersTheLawOfDemeter,Don'tTalkToStrangers
  23. 23. Cake Development Corporation DoesItScale?DoesItScale? IgnoreThePerformanceBenchmarksIgnoreThePerformanceBenchmarks
  24. 24. Cake Development Corporation Scalemeansmanythings...Scalemeansmanythings... > Dataprocessing> Dataprocessing > Requestconcurrency> Requestconcurrency > Cachingstrategy> Cachingstrategy > Storageengine> Storageengine > Development effort> Development effort > Maintenancecost> Maintenancecost
  25. 25. Cake Development Corporation ThinkAboutYourDataThinkAboutYourData YourDatabaseSchema IsYourAchillesHeelYourDatabaseSchema IsYourAchillesHeel
  26. 26. Cake Development Corporation ThinkAheadWithYourDataThinkAheadWithYourData AvoidStaleData,UseQueuing,CronTasksAnd Data WarehousingAvoidStaleData,UseQueuing,CronTasksAnd Data Warehousing
  27. 27. Cake Development Corporation AvoidTheHypeAvoidTheHype Don'tFollowTheHerd,BeGuidedOnlyBy ResultsDon'tFollowTheHerd,BeGuidedOnlyBy Results
  28. 28. Cake Development Corporation RespectTheProfessionRespectTheProfession TheCheaperAlternativeIsAlwaysMoreExpensiveLaterTheCheaperAlternativeIsAlwaysMoreExpensiveLater
  29. 29. Cake Development Corporation ReduceTechnicalDebtReduceTechnicalDebt BeRealisticAboutCornersYou Cut AndShortcutsYou TakeBeRealisticAboutCornersYou Cut AndShortcutsYou Take
  30. 30. Cake Development Corporation BudgetConstraintsAreRealBudgetConstraintsAreReal ContemplateFutureDealingOfAccumulated DebtContemplateFutureDealingOfAccumulated Debt
  31. 31. Cake Development Corporation VersionControlVersionControl ThereIsThereIs NONO ExcuseToNotVersion YourSourceCodeExcuseToNotVersion YourSourceCode
  32. 32. Cake Development Corporation Test,Test,TestTest,Test,Test ReduceCoverageReduceCoverage BeforeBefore YouAvoidTestingAnythingYouAvoidTestingAnything
  33. 33. Cake Development Corporation PracticePractice
  34. 34. Cake Development Corporation CakeDCGitWorkflowCakeDCGitWorkflow http://cakedc.com/git-workflowhttp://cakedc.com/git-workflow
  35. 35. Cake Development Corporation GitDevelopmentStrategyGitDevelopmentStrategy
  36. 36. Cake Development Corporation Stability,Quality& ConsistencyStability,Quality& Consistency
  37. 37. Cake Development Corporation Debug KitDebug Kit https://github.com/cakephp/debug_kithttps://github.com/cakephp/debug_kit
  38. 38. Cake Development Corporation CakeDCMigrationsCakeDCMigrations https://github.com/CakeDC/migrationshttps://github.com/CakeDC/migrations
  39. 39. Cake Development Corporation CakeDependencyCakeDependency https://github.com/jameswatts/cake-dependencyhttps://github.com/jameswatts/cake-dependency
  40. 40. Cake Development Corporation DIFeatures...DIFeatures... > Registerclasses,objectsorcallbacks> Registerclasses,objectsorcallbacks > ConstructorandSetterinjection> ConstructorandSetterinjection > Lazyloading> Lazyloading > Dependencyscopes> Dependencyscopes > Observers> Observers
  41. 41. Cake Development Corporation Registera ServiceRegistera Service Di::add('Foo', [ 'className' => 'Example', 'classPath' => 'Plugin.Path' ]); Di::add('Foo', $object); Di::add('Foo', function() use ($something) { // return service instance });
  42. 42. Cake Development Corporation ConstructorAndSetterInjectionConstructorAndSetterInjection Di::add('Foo', [ 'className' => 'Example', 'classPath' => 'Plugin.Path', 'params' => [ 'bar' => Di::load('Bar') ] ]); Di::add('Foo', [ 'className' => 'Example', 'classPath' => 'Plugin.Path', 'setters' => [ 'setBar' => [ 'bar' => Di::load('Bar') ] ] ]);
  43. 43. Cake Development Corporation UsingObserversUsingObservers Di::observe([ 'MyInterface', 'AbstractClass' ], [ 'setters' => [ 'setFactory' => Di::load('Factory') ] ]);
  44. 44. Cake Development Corporation CakeToolkitCakeToolkit https://github.com/jameswatts/cake-toolkithttps://github.com/jameswatts/cake-toolkit
  45. 45. Cake Development Corporation CTKFeatures...CTKFeatures... > Object-orienteddesign> Object-orienteddesign > Abstractionandencapsulation> Abstractionandencapsulation > Separationofconcerns> Separationofconcerns > Extensiblearchitecture> Extensiblearchitecture > Plug andplay> Plug andplay > Legacysupport> Legacysupport
  46. 46. Cake Development Corporation Object-Oriented ViewsObject-Oriented Views class IndexView extends CtkView { public $factories = ['Ctk.Html', 'Ctk.Js']; public function build() { // create a HTML div $div = $this->Html->Div(); // create a HTML button $button = $this->Html->Button([ 'value' => __('Click Me') ]); // add the button to the div $div->add($button); // add the div to the view $this->add($div); } }
  47. 47. Cake Development Corporation ViewExtensibilityViewExtensibility class IndexView extends CtkView { public $factories = ['Ctk.Html', 'Ctk.Js']; public function build() { $div = $this->Html->Div(); $div->add($this->buildButton()); $this->add($div); } public function buildButton($value) { return $this->Html->Button([ 'value' => __($value) ]); } }
  48. 48. Cake Development Corporation AttachingEventsAttachingEvents // create a HTML button $button = $this->Html->Button([ 'value' => __('Click Me') ]); // bind an event to the button $button->bind('click', $this->Js->Alert([ 'text' => __('Hello World') ]));
  49. 49. Cake Development Corporation ReusingObjectsInLegacyViewsReusingObjectsInLegacyViews <div id=”example”> <?php echo $this->Factory->Html->Span([ 'text' => __('Hello World') ]); ?> </div>
  50. 50. Cake Development Corporation CakeMarkupLanguageCakeMarkupLanguage https://github.com/jameswatts/cake-markup-languagehttps://github.com/jameswatts/cake-markup-language
  51. 51. Cake Development Corporation CakeMLFeatures...CakeMLFeatures... > Familiarsyntax> Familiarsyntax > Readyfordesigners> Readyfordesigners > Simpletemplating> Simpletemplating > Extensiblebydesign> Extensiblebydesign > Plug andplay> Plug andplay > Legacysupport> Legacysupport
  52. 52. Cake Development Corporation MarkupMarkup <div id="example"> <cake:out value="Hello World" /> </div> <div id="%{foo}"> <cake:out value="#{Hola Mundo}" /> </div> <cake:out value="%{foo}" default="Nothing here" />
  53. 53. Cake Development Corporation ControlStructuresControlStructures <php:if expr="!empty(%{foo})"> <cake:out value="%{foo}" /> <php:else /> <cake:out value="Oops, no value" /> </php:if> <php:foreach var="products" default="No products found"> <cake:out value="%{COUNT}. %{KEY} = %{VALUE}" /> </php:foreach>
  54. 54. Cake Development Corporation FrameworkFeaturesFrameworkFeatures <cake:link value="#{Blog}" url="['controller' => 'Posts']" /> <cake:form model="Post" options="['action' => 'add']"> <cake:input field="Post.title" /> </cake:form> <cake:helper name="Foo" call="run" args="['bar', 123]" /> <cake:element name="sidebar" options="['foo' => %{bar}]" />
  55. 55. Cake Development Corporation ThanksThanks
  56. 56. Cake Development Corporation CakePHP2ApplicationCookbookCakePHP2ApplicationCookbook https://packtpub.com/web-development/cakephp-2-application-cookbookhttps://packtpub.com/web-development/cakephp-2-application-cookbook

×