PHP OOP Design Patterns | Factory Method

Поділитися
Вставка
  • Опубліковано 24 сер 2024
  • ℹ Factory method is a simple design pattern which enables you to delegate the creation of objects to a dedicated class...keeping your client code lean and observing the single responsibility principle.
    🆓 Join garyclarke.tech for course DISCOUNTS and a FREE Docker + PHP course (worth $49)
    www.garyclarke...
    💻Source code here:
    github.com/Gar...
    👇Follow me on Social Media:
    Twitter: / garyclarketech
    Linkedin: / garyclarketech
    💕Show support:
    www.paypal.com...

КОМЕНТАРІ • 24

  • @adelhishem1
    @adelhishem1 3 роки тому

    Nice one Gary, keep them coming these intermediate videos. Thanks a lot for sharing.

  • @shahosanandaji9894
    @shahosanandaji9894 Рік тому

    Great, as always, Gary!

  • @FrankLandry
    @FrankLandry 3 роки тому

    Very information Gary. Thank you.

  • @sandyvga
    @sandyvga Рік тому

    Nicely explained with good example.

  • @DanielK48
    @DanielK48 3 роки тому

    Great video! Would love to see series on design patterns :)

  • @vinsouz
    @vinsouz 3 роки тому

    Thank you for your work again !

  • @operico
    @operico 3 роки тому

    Thanks for sharing! Awesome video!

  • @ApplicableProgramming
    @ApplicableProgramming 3 роки тому +2

    Well explained, I like that you used real life example. What are the advantages of using Factory Method rather then simple if-else in the controller?

    • @GaryClarkeTech
      @GaryClarkeTech  3 роки тому

      Ah thanks a lot...I appreciate your appreciation!

  • @rahulchavan.
    @rahulchavan. Рік тому

    NIce Explanation, if i am not wrong decorator design pattern makes more sense for this example, modify the behaviour of free plan objects depending upon the plans. if no then please explain why factory pattern is more suitable.

  • @boultim
    @boultim 3 роки тому

    nice video good job

  • @stylesg7818
    @stylesg7818 Рік тому

    Thank you for the great videos.
    Question: When is it best to favour inheritance over composition?
    Is it best to extend abstract classes or code to an interface? Are they any differences?

    • @GaryClarkeTech
      @GaryClarkeTech  Рік тому

      Inheritance over composition where composition definitely won't work. Only use inheritance when that is exactly what you need i.e. the subclass is a more custom version of the parent...not just if you want to add some more functionality.
      Abstract v interface..if each subclass needs some functionality which will always be the same, then use a abstract...otherwise use an interface..or..quite commonly you will see that the abstract class implements an interface...these are not hard and fast rules..more like guidelines and it's stuff that you'll just pick up as you gain experience.
      I cover all of the above quite a lot in Learn Object Oriented PHP:
      www.garyclarke.tech/p/learn-object-oriented-php
      Hope you check it out 👍

  • @FrankLandry
    @FrankLandry 3 роки тому +1

    One more comment, while your tutorial is great and informational, you might also want to highlight sanitizing anything that gets passed to the POST and GET superglobals in a basic way. Just a suggestion.

    • @GaryClarkeTech
      @GaryClarkeTech  3 роки тому

      Thanks Frank...that's a sensible suggestion.

  • @dustinandband
    @dustinandband 2 роки тому

    Does the web server automatically make separate php files visible to others that are in the same namespace (so no need to use ‘include’ or ‘require’ keywords)? That is the only part of this tutorial that’s unclear for viewers working with an IDE and not launching a web server for testing.

    • @GaryClarkeTech
      @GaryClarkeTech  2 роки тому

      You don't need a running web server for namespaces to work. You just need to have autoloading enabled.

  • @theman7050
    @theman7050 Рік тому

    When do you use double slashes like these: \\

    • @GaryClarkeTech
      @GaryClarkeTech  Рік тому +1

      If you are writing a namespace inside a string mainly because \ on its own means escape the next character...but you need a \ in a namespace

    • @theman7050
      @theman7050 Рік тому

      @@GaryClarkeTech wow thanks man. It makes sense now.
      But in some wordpress tutorials I have also seen the name space, while being a string, use a single slash and also prefixed with a single slash like so:
      '\App\Inc\Plans\Free'
      It is like that in my spl_autoload function which I copied from somewhere. Im not sure why are single slashes used there or why a slash prefixes the namespace. Could you plz help me understand? Thanks for the amazing value in ur videos :D