PHP Design Patterns in REAL life - Student code review #1

Поділитися
Вставка
  • Опубліковано 2 лис 2024

КОМЕНТАРІ • 140

  • @raylawlor4887
    @raylawlor4887 3 роки тому +13

    Thank you for this. It's great to see these types of tutorials that move beyond "tutorial level" and into real code. Please keep them coming, they are a big help. :)

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

      Glad you like it Ray. This is something I wish was there while I was trying to figure out some of the design patterns. Are you following other videos here, or have you found this video by searching for something?

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

      @@ApplicableProgramming I specifically searched for design patterns. I’m reading Matt Zandstra’s book and came on UA-cam to get some good examples.
      Your tutorial is “right on the money” regarding patterns and how a real world app might work.
      I’ll be checking out your other videos ASAP.

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

      @@raylawlor4887 Thanks, that is glad to hear. What is your biggest problem with Design Patterns? For me it was when to actually use them

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

      @@ApplicableProgramming I had written an extension for Joomla and although it worked well, it was difficult to maintain since I had simply combined the objects with lots of static "factory" type methods. Everything was a mess.
      I then began reading up about how to build a large application - but a lot of the examples are "hello world" or "to-do list" apps, rather than a view on how to organise a large project efficiently.
      So after reading most of Matt Zandstra's book, I then began rewriting the component using the Factory Pattern - using factories to create the objects etc. I'm about 80% through the refactoring and it "feels" much better to work with... all my client code is neater etc.

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

      @@raylawlor4887 Yeah, factories are underappreciated. Although to be honest, for me personally the Dependency Injection was the AHA things, as it made it very easy to separate models and objects. I used to cram code all over the place, now knowing how to make objects communicate without being tightly coupled. And dependency injection allowed me some level of separating concerns. I find myself using it the most, and other patterns... they appear here and there but most of the time I do not think about them actively.
      Do you have latest edition of the book, how do you find it? I wanted to buy it for inspiration, I am planning to write a book about practical use of design patterns in php

  • @earl5954
    @earl5954 3 роки тому +7

    I hope more programmers/coders/web devs find this channel.
    This is what i call practical learning

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

      Well thank you Earl, it is highly appreciated. You could.. share this video on some facebook/redditt groups that you think can benefit others :)

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

      Shared it to a fb group i belong.

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

      @@earl5954 Thank you very much sir! :)
      Do you use design patterns in your projects?

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

      Yes, i have used dependency injection and factory before. I have this exercise where i (tried to) make an mvc framework.

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

      @@earl5954 is it something for work, or for a job interview?

  • @ianmcbride1867
    @ianmcbride1867 2 місяці тому +1

    Awesome explanations! This is the exact type of video ive been looking for. Thanks!
    EDIT: Not sure if you plan on being more active on here but i subscribed anyway. Would love to see more code review type videos!

    • @ApplicableProgramming
      @ApplicableProgramming  2 місяці тому +1

      Thank you for your nice comment, glad you enjoyed the content.
      I do plan on being active, just when the time permits it. It takes a lot of time writing good, non-trivial tutorials.
      would you like to see something similar for JavaScript? Or something non-code related perhaps?

    • @ianmcbride1867
      @ianmcbride1867 2 місяці тому

      ​@@ApplicableProgramming I hear ya, quality over quantity for sure. I would be interested in JavaScript videos like this as well or anything about improving code.
      I'm just mostly self-taught so it's nice to see someone critique code of which I can apply to my code since I don't have an actual teacher telling me what I'm doing right or wrong.

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

    Inace svaka cast na svemu i hvala, dosta toga sam naucio prateci Vas.
    Pozdrav

  • @alifallahrn
    @alifallahrn 3 роки тому +3

    Excellent. Please continue the code review videos

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

      Glad you liked it. Do you have some code to be reviewed?

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

      @@ApplicableProgramming Yes, I have a WordPress plugin, do you also review code related to the WordPress plugin?

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

      @@alifallahrn I guess I could, but I never actually made a WP plugin and to be honest not sure how much you can go with it. It has to follow WP rules and tools, which is not exactly OOP or using some advanced principles?

  • @hochihuynh2024
    @hochihuynh2024 2 роки тому +1

    Thank for you lessons. Please add more about PHP Design Pattern in real life.

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

      Thanks, sure thing! Do you maybe have some code I could use in the video?
      It doesn't have to work even

  • @rajabhishek2936
    @rajabhishek2936 3 роки тому +3

    Awosem video. Please upload more video Quickley

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

      yup, trying. but it takes 20-30 hours per video, so... it can go just as fast as it can go

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

    I got a job working as a backend engineer using laravel, when I got the job I was kind of shocked, because I am not qualified, and before you say "don't be negative", I didn't even know what a design pattern was until like a month ago. I need help grasping design principles because I think learning those principles will help me grasp concepts easier, as it's part of the rhetoric at my work. I have some exposure with python and PHP but nothing serious or impressive, I am not being derogatory here, I have done nothing with my programming skills really like completing an application, building a large project, using models, controllers, I've learned a lot at work but I definitely need to be more independent and come up with my own solutions to issues. Would your course work for me? I don't even know where to start. I feel pretty lost and I know there's tons of stuff online but, what if my PHP isn't good enough to use laravel and I need some principles to get better? I don't know.

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

      Hi J O. That is a great question, however I do not know the answer to be honest. My course will surely not help you with everything you mentioned above, I do believe it will help you with some parts. But I understand the feeling you have, every single one of us had it when we started working. And that is probably the only way to start programming, or pretty much anything else. I have a lot of friends who are doctors, and they had the exact same problem, so... It just has to be dealt with.
      The good thing is that there are just so many things that you need to learn, and then you are finished. Except that then you will find ten or more new things that you need to learn, and the cycle repeats. You will always have those doubts, I signed for a new job last month, and I have exact same doubts even though I have over 18 years of experience in the programming. There is always something you will not know. Just use that "discomfort" as motivation to learn, and one day that is it. You will be helping others. And if Php and Laravel are not good enough, then just find something else and go with that. It takes about five years to become somewhat comfortable with programming, after that you get used to being uncomfortable :)

    • @jordanolson11
      @jordanolson11 2 роки тому +1

      @@ApplicableProgramming I guesss my issue is that I have been in the field for 1-+ years, I worked on a variety of teams and developed with them, but my OOP knowledge seemed to suffer the most, I found ways to survive by getting help, and doing what I could. Sometimes I wonder if I'm hired for my personality, not for my skills. Part of me is worried I don't know how to learn, or I can't, so I've dug myself into a hole. I want to find something that finally pushes me, finally makes me take all of this seriously, but I can't, and I wonder if I can't because my brain trained itself not to enjoy things I couldn't just pick up and understand immediately. I'm worried if I pick up your course, I give up half way through, or don't practice enough, a lot of it just comes down to my terrible education as a kid. I never studied, therefor never learned how to study, and when you say you learn things, I don't know where to start, and what to learn.
      Part of all of this is obviously due to me not spending enough time at home, around 30 minutes to an hour daily learning the things I am stuck on, and developing my own projects. I figure this course could help me a lot, but I'm worried I might end up giving up again. Thanks for responding to my comment, I appreciate you taking the time, I would love to commit to something but it really just seems that it's more than just design patterns, I need to fundamentally change my thinking and lifestyle to spending time daily at home practicing PHP and laravel to get better, I just wish there was a more effective approach, I guess a "one size fits all" which I understand can't exist due to how different our brains are. Sometimes I just think it's my brain though, something wrong with me, which might be true, and might be what I need to help me change so I can be a better developer. I think the problem is I always am seeking an instructor, someone to teach me, because I can't teach myself because I'm missing some essential thing I missed in school or in my development, and I just need to spend more time doing personal projects I guess, Thanks for reading my very long first message.

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

      @@jordanolson11 I got you man, I understand what you are saying. We do have a "accountability" dimension in the student community, although a lot of people use course to find new jobs and then they focus on the new tasks. But I do have about ten students I am working with right now, we usually meet one on one, we make a plan and they push themselves towards it. We meet once in few weeks and we discuss their progress and problems. I guess that is typical mentorship. It helps me understand what they struggle with so that I can make better videos, it helps them when they get stuck. They do not pay me for that of course, as I can "write down" those hours as assistance to students. If that sounds interesting, it would not be a problem for me to meet with you on 1h video once a month or so (probably after the holidays). But it is on a voluntary basis, so I cannot promise availability and results. But I try :)
      btw I talk about your problem a bit in this video ua-cam.com/video/thnF83f3LTo/v-deo.html
      and I will think a bit more about your problem, and perhaps make a new video one day.
      What helped me when I was at the same place as you, was that I got a baby and then I embraced responsibility for it. That gave me clear purpose on whys and hows. Then I found a book from Jordan Peterson 12 rules for life, and that gave me confidence to push forward.
      May I ask why have you started programming in the first place?

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

    thank you for this great video we need more videos for php design patterns

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

    IMO even if someone is a beginner in pop, one of the first things that must be learnt is composer and namespaces

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

      i guess it depends on the type of projects you are working on. they are important, but not sure if they are one of the first things. Useful as hell, for sure

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

      @@ApplicableProgramming After learning the mechanics of OOP and some basic usage I think it is a must. Use composer at least not to require the classes manually is one of the best things that ever happened to php. Also using namespaces especially when are learning design patterns is pattern itself. Also I don't think there are projects that don''t use namespaces and composer out there. Better bite the bullet and learn it early IMO!

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

    How many years have you been coding in OOP PHP, and where did you make it made clear that someone who is trying to learn the correct approach to coding in OO PHP will probably not be able to reproduce anything close to what you exhibit here, without a firm graps of what can be done? As much as I would love to be able to code clean crisp PHP code, you can't imagine how discouraging it was to watch.

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

      Oh come on, don't be discouraged watching someone on a prepared video, who is reading everything from a teleprompter :)
      Be encouraged that you discovered what you can learn next instead. There are honestly not that many things to learn if you think about it. If you learn DRY and SOLID principles (which are like 6 concepts), and you learn say 6 popular design patterns (three of which I mentioned in this video), you will be pretty much on my level of knowledge. Say that you learn one principle for a month, in one year you are on a very decent level. Not that much if you think about it, considering how doctors spend about 5 years just to be able to start working (and then realize they have no clue what to do).
      I've been working professionally for 17 years with php, I was quite lucky to jump straight in object oriented when it was introduced in php4, but for first few years it was more or less spaghetti OOP until I got mad and started really learning difficult concepts. Real breakthrough happened when I started learning Java and even TypeScript as those are more robust and strict then PHP, but also when I started using Zend framework and Magento, as those are on a quite different level. But Laravel or CodeIgniter can also help a lot (watch my video on analyzing their source code if you haven't)
      Have you been working with php for some time, or just started learning recently?

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

      Excellent points

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

    Mislim da bi bilo zanimljivo. Hvala

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

    Thanks a lot! This was very helpful for me.

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

      Glad it helped Hasnat. Do you have some code that i could review?

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

      @@ApplicableProgramming I will try to provide some code soon. Thanks again for you time. :)

  • @emekatimothyiloba699
    @emekatimothyiloba699 Рік тому +2

    What's your advice to a dev who uses an OOP framework efficeintly (Laravel) but does not really know how to build apps from scratch with OOP (PHP)

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

      That is a good question, I would say do what you find interesting. But I do not see a scenario where you do not end up knowing programming basics... So why not learn it sooner then later :

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

      @@ApplicableProgramming Thank you so much for your reply. Your UA-cam channel is a blessing not just to me buy to many others. I pray that God rewards you. Please sir how can I sign up for your mentorship

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

    more of this videos, plz 😍😍😍😍

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

    Voleo bih kada biste mogli snimiti par primera kako uciti za Zend, nacine koje ste Vi korstili da testirste i ucite phpove funkcije i sve ostalo...

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

    Hvala

  • @nasossoulis9495
    @nasossoulis9495 8 місяців тому +1

    Very nice tutorial! Thank you!

    • @ApplicableProgramming
      @ApplicableProgramming  8 місяців тому +1

      Thank you mister. Are you using frameworks?

    • @nasossoulis9495
      @nasossoulis9495 8 місяців тому +1

      @@ApplicableProgramming yes, i use laravel, which it uses design patterns, so if i understand some designs patterns, i can understand laravel better.

    • @ApplicableProgramming
      @ApplicableProgramming  8 місяців тому

      @@nasossoulis9495 nice. that is a good thing to learn then :)

  • @orhanahmadov9381
    @orhanahmadov9381 4 місяці тому +1

    Great video, thanks.

  • @groovebird812
    @groovebird812 2 роки тому +1

    Hi, super useful video, thank you. How would you pass the param to the parseRoute method by using the makeFromRouter method of the controller factory? Is it better to only use the constructor of the router class for passing the uri?

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

      That is a great question grooverbird, as usually the answer is "it depends". You can set it in the constructor in this particular case creating a hard dependency. If you would expand router later so that it works with different types of routes (something from database, or something from .xml file) then you might consider soft dependency using a method like "setRoute()" or even use a different strategy per route type (databaseRouteStrategy, xmlRouteStrategy etc).
      I would always advise to start simple and expand when needed, but even when starting simple think of where it could go in the future, just so you do not block yourself right away.
      This whole example is a bit overkill, as it really works as it should. The issue is that the applicant got instructed to actually go overboard and use some design patterns intentionally, so then you do what you need to do.
      Or did I misunderstand your question?

    • @groovebird812
      @groovebird812 2 роки тому +1

      @@ApplicableProgramming thank you, you didn't misunderstand the question. In the Video there are 2 calls of $router->parseRoute('/search') or $router->parseRoute('/user/logout') and after setting up the dependency injection with the makeFromRouter method i thougt how we can use the parseRoute method with the params it was earlier working :-) That was the background of my question. It is often hard to create the right architecture :-)

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

      @@groovebird812 Yeah you can get it only right with the information you have at the time. In real life you have to refactor all the time. How did you find this video if I may ask, searched for design patterns?

    • @groovebird812
      @groovebird812 2 роки тому +1

      @@ApplicableProgramming yes i searched for PHP Design Patterns in the youtube seachbar and found your channel :-) I will watch the other videos as well.

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

      @@groovebird812 Great, welcome to the channel :)

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

    Great video bro 😎

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

    Great video. I learned a lot

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

      Thank you Jose, glad you liked it!
      Do you use design patterns in real projects?

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

    That's a great video and clear explaination. But all due respect I think it's best to avoid reinventing the wheel. PHP framework like Laravel addresses all these issues following SOLID principles plus providing tons of developers friendly performance effective features which helps one to focus on important business logic.

    • @ApplicableProgramming
      @ApplicableProgramming  Рік тому +4

      Oh definitively, and I would not advise anyone to start writing this from scratch, it will never be better then any of the shelf platform.
      But if you have followed the entire video, this code was asked and submitted to a job interview, and there you get to very clearly separate programmers from "Laravel users". The programmers know how the wheel works from the inside :)
      It comes to a point on the career when you have to differentiate from other programmers, and that is not by knowing the newest version of Laravel, but by knowing the principles Laravel uses internally. In this video I basically talk about that ua-cam.com/video/bjrbQ2qf0vs/v-deo.html

  • @JohnSmith-pq3nw
    @JohnSmith-pq3nw 3 роки тому +1

    If it comes to methods in HomeController(showing diffrent views that you said could be changed to one function that as an argument takes name of the view and prints it) this is the way that frameworks like symfony do it and it makes sense if in the future you would want to use some logic in them. So is it that important to make this change?

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

      Good question. Most Popular answer is "it depends". I personally would go with the easiest solution first, and refactor as needed. If there is no need, then do not complicate it.
      But for context, this project was made in order to show to employer that you can advanced things, so it is just a show of. It works fine the way it is now in the beginning, so whatever you would do to it is also "correct", as long as you can explain your reasoning. So you want to show something that you can, and communicate with others what was you thinking, why that particular decision and solution, and what are the alternatives if someone tells you that it is "wrong".
      If you asked me your question on interview, I would take it sad a plus, as you know how simphony works, you mentioned reasons behind it, and you were questioning the decision. So... Good thinking there :)

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

      In private projects? Yeah, used yii, code igniter, fuel and a bit of symphony. Lately mostly Laravel.
      Not in this series, although it is obviously inspired by frameworks.
      You?

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

    Pozdrav svima,
    Takodje i Vama Dalibore.
    Zelim prokomentarisati Vas kod nakon refaktoringa.
    Zadatak je mali, ali tako mala stvar kasnije se moze razviti u nesto dosta ozbiljnije i opsirnije.
    Za tako nesto trebala bi nam abstrakcija.
    Class folder sam po sebi ne moze biti abstraktan za dalji razvitak aplikacije. Recimo da se odnosi na jedan deo aplikacije koji je napisan, i dobro radi sa singleton i factory paternima.
    Medjutim prava snaga DI paterna jeste upravo u celoj abstrakciji.
    Odnosno kompoziciji koja se zasniva na Contracts, Abstract classes, Classes, Services etc..
    Recimo da mozemo napraviti interface koji bi mogao biti ugovor koji servis mora implementirati, i taj servis bi mogao vratiti samo instancu PDO, ili Redis, Memcached etc...
    Sa takvom konstrukcijom folder strukture izuzetno je lako koristiti Dependency Inversion, Flip dependency between low level modules.
    Samim takvim sistemom mozemo lako dodati composer pakete recimo DOCTRINE/DBAL i jako lako zameniti PDO servis.
    Takodje, autoloader i composer je obavezan za dalji razvitak aplikacije.
    Namespaces, packages, etc..
    Mozda sam ja pogresno razumeo zadatak.
    Svakako bih pre svega umesto custom rutera, izabrao recimo FastRoute/Nikic, naravno objasnicu i zasto.
    Zamislimo slucaj da nam je za apstrakciju koju sam opisao potreban kontejner za sve te zavisnosti.
    Mozemo iskoristiti psr11 container i gotovo sami kroz par metoda postaviti zavisnosti za konstruktore klasa, ali onda moramo dodati metode i za dependency u metodama etc...
    Lakse je iskoristi symphony ContainerByilder, gotovo isti slucaj kao i sa PDO.
    Otprilike sam zeleo samo govoriti o daljoj abstrakciji.
    Vas nacin je ok i radi, ali za nesto sto se zove app za 1 dan 😁

    • @ApplicableProgramming
      @ApplicableProgramming  Рік тому +2

      Zdravo ZeaL. Generalno se slazem sa tobom, ima dosta nacina dalje da se uprosti (ili zakomplikuje) kod za potrebe daljeg razvoja u nesto ozbiljnije. Naravno uvek je balans vremena, kompleksiteta i prevremene optimizacije.
      Mada ovaj konkretan slucaj u videu je zadatak koji je radjen za tehnicki intervju, i iskreno mislim da bi bio nepotrebno kompleksan da se ubacilo sve sto si spomenuo. Prvo sto ne bi bilo vremena, drugo sto bi potencialno omasio ceo zadatak jer na intervjuu za posao je poenta pokazati kako kandidat razume mehanizme kroz svoju implementaciju istih. Da poslodavac moze da oceni nivo znanja koncepta koje kandidat ima. Ako kandidat koristi gotove biblioteke za routing i ostalo, onda gubi mogucnost da pokaze da razume kako routing (i ostalo) sustinski radi.
      Ja bih radije da mi neko napravi primitivan router u 10 linija koda i objasni zasto ga je tako napravio, nego da ima jednu liniju $r->addRoute() koju garantovano ne zna sta radi, osim ako je bio contributor na FastRoute projektu. Prvi slucaj pokazuje da znas kako to radi, drugi pokazuje da znas da koristis gotove biblioteke :)

  • @toblamabor7072
    @toblamabor7072 10 місяців тому +1

    good for beginners but does not help for the people who already codes since 10 years :D any advanced video to suggest?

    • @ApplicableProgramming
      @ApplicableProgramming  10 місяців тому

      Hehe, you are then already above my level of knowledge :)
      usually at that level you are the one teaching others from your experience, mainly because there are fewer and fewer advanced tips and tutorials :)
      but try this video maybe ua-cam.com/video/wHrkL2SKjjk/v-deo.html
      or this one ua-cam.com/video/a7bgGhSTTb0/v-deo.html&ab_channel=ApplicableProgramming

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

    It's a really great video, thanks a lot for sharing it

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

      Thank you Ahmed. Your other comment disappeared for some reason, but I would advise to try what I was doing in this video, get your objects outside the application, and try to make them work. That will force you to use SOLID principles, as well as Design Patterns. And sit down, spend three weeks and master solid principles and couple of design patterns, then you will notice your skills going up.
      Are you maybe doing some automated testing?

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

      I am not sure about the missed comments,
      Thaanks for your advice I will try to do this way for a while, for testing I am thinking to write unit tests within the refactoring

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

      @@ahmedslink That is a good step I would say. Ir you do not want to go full with unit testing, you can just isolate classes like I shown in this video

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

      Got the point, I will use the Idea and see the results

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

      Thanks for the advice 🙏

  • @yuvrajsingh-nn5wz
    @yuvrajsingh-nn5wz 7 місяців тому

    Superb :)

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

    How can I call execute function from Controller class ?

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

      At what point in video are you referring to? not sure what you are asking, but you just call execute() method. Or?

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

      @@ApplicableProgramming At newly index refactor file where route returns controller like HomeController on 'results' route but how to call exact method for that on the fly .... using execute method . Thanks in advance

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

      @@aizazaziz5636 Its been a while since I made this video, but check this code here, I would imagine it does the same thing, just with a different name (runAction instead of execute) github.com/applicable-programming/darwin-cms/blob/d82ea322e0e33b052328f09878b54c5c8196d8f1/public/index.php#L46

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

      @@ApplicableProgramming Thanks

  • @AA-cc7hj
    @AA-cc7hj 2 роки тому +1

    what is the difference between init() and __construct() ?

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

      God question. __construct() is a built in magic method that PHP will call every time an object is created. Init() is just a method like any other, you have to call it yourself. Have you seen that in this video, or some framework?

    • @AA-cc7hj
      @AA-cc7hj 2 роки тому +1

      @@ApplicableProgramming
      In this video when you made singleton fordb connection you made the singleton inside init() function not construct()... That's why I asked.

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

      @@AA-cc7hj oh i see... Yeah, the singleton in this video is not an object created with "new" keyword, this the constructor is not called. In fact, the whole point of singleton is that you cannot create an object from it, it should not be possible by design. Thus the constructor would be useless as it would never be called. But we need to initiate the singleton instance, for that we need to use custom method, in our case the "init()", but you can change it's name to whatever makes more sense. Have you used singletons before?

    • @AA-cc7hj
      @AA-cc7hj 2 роки тому

      @@ApplicableProgramming Thanks alot

  • @kuthub1989
    @kuthub1989 3 роки тому +3

    is your MVC series finished?

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

      Not yet, I have plans on few more videos at least.
      But to be honest, that project is one of the "always ready, never finished" So, I do not think it will ever be finished. Don't even know what that means for a project :)

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

      @@ApplicableProgramming thank you.

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

      @@kuthub1989 have you watched all MVC CMS series?

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

      @@ApplicableProgramming watched upto 5th video.

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

      @@kuthub1989 That is great. Then you have at least 10 more before I need to make another video in the course :)

  • @strictlyunreal
    @strictlyunreal 2 місяці тому +1

    36:33 - 33:39 I'm sure that that made sense in your head! But we're not living in your head, mate!

    • @ApplicableProgramming
      @ApplicableProgramming  2 місяці тому

      what are you referring to exactly, that router explanation was confusing?

  • @DavidSmith-ef4eh
    @DavidSmith-ef4eh 2 роки тому +1

    I don't like how you handled the config class. It's prone to errors based on typos. Better if you defined props on it instead of using an array/map... But thats the problem with PHP, it lacks many features other languages have.

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

      That is a good point. PHP does actually support now typing, so you could define config with interfaces, but you do lack a flexibility in both configuring and using config variables, and you reduce the speed of development as you need to change several things to get up to speed. Config is generally used for environment specific data, and quite often using .env format which I mentioned, which does not allow for typing. And yes I agree, I had quite several times problems when variables were not defined in my local .env file, and you have no idea that they should be defined.
      However, due to all reasons above all major frameworks use strings for configs:
      Laravel laravel.com/docs/8.x/configuration#accessing-configuration-values
      Yii2 www.yiwork.com/doc/guide/2.0/en/concept-configurations
      and even Zend framework.zend.com/manual/2.1/en/modules/zend.config.introduction.html
      But of course, it is not a rule written in stone so we can still use whatever we want to :)
      You mentioned maps, I assume you have a background in another language?

    • @DavidSmith-ef4eh
      @DavidSmith-ef4eh 2 роки тому +1

      ​@@ApplicableProgramming Yeah, I am coming from a TS background where you have generics and an incredible type system. I know you could have those things with dockblocks, but it's uncesessary typing and code bloat and my vscode extension (php intelephense can't read generics from dockblocks). Also, I wanted to use reflection to generate graphql types based on the class type definition, and I can't do anything with arrays...
      I wish they would add features to php faster. Other languages seem miles ahead.

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

      @@DavidSmith-ef4eh yeah that makes sense. I use TS often and am very used to that type of data and type of thinking. But you have to remember that PHP is typeless language, just like JavaScript. It might get some typing, but it will never become Java (for better or for worse). Same with JavaScript, they figured it will never work so the typescript was born. But you do work on both ends? Single page applications?

    • @DavidSmith-ef4eh
      @DavidSmith-ef4eh 2 роки тому +1

      @@ApplicableProgramming yeah, but mostly backend. Was charged to implement a simple api integration, and chose PHP as the language, since they already owned a server with php on it. But then the employer was happy with the results and delivery time, and gave me bunch of other features to implement, and I kept doing it in PHP in a OOP fashion and following DDD to some degree by Uncle Bob. And now I am watching videos like yours to keep improving, specially to recognise when its appropriate to use design patterns...

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

      ​@@DavidSmith-ef4eh Firstly, to be in the same sentence as the teachings of Uncle Bob is a privilege on its own, so thank you for that :)
      About when to use design patterns.... I get that a lot, and am starting to thinking that we in essence always use design patterns, just that some do not have official names for all. It is just a "common thing" to organize code in some particular way, or transfer data between objects one or the other way. I mean, we have to do it somehow anyway, and chances are we are using something that someone else already proved as a suggestion, or a good tip, or a proven solution. Which, in practice, is what a design pattern is. A proven way of solving some problem.
      So... I say use design patterns in 100% of the code :D but yeah, it is good to recognize when to use the popular ones that have a name :)
      But you seem to go quite deep into the principles and want to understand them on a deeper level (something that most of people never bother to do, and I didn't bother for many years).
      How long have you been programming if I may ask?

  • @Quynn-Oneal
    @Quynn-Oneal 3 роки тому +1

    27:38 is it possible to create an abstract singleton class then extend that with a concrete final singleton class?
    Thanks for your time for creating this video.

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

      I've never built an abstract singleton, I guess it should be possible. My first thought is that the properties of the first created singleton would be shared with all other classes, not sure if this is the behavior I would expect from my models (at least I think it would behave this way). It somehow defeats the purpose of the true singleton (a class that has only one object, and cannot be extended and cloned), as abstract singleton would do exactly that, defeat all benefits and definitions of a true singleton. You could have static fields and methods, but static methods do not define singleton.
      Do you have an example of why would you want to do this, what problems does it solve?

    • @Quynn-Oneal
      @Quynn-Oneal 3 роки тому

      @@ApplicableProgramming I have never done that but after seeing you are calling self() to create an instance. I thought that might be a good idea to have an abstract class just to follow DRY.

  • @strictlyunreal
    @strictlyunreal 2 місяці тому +1

    34:22 What a crappy interface PHP Storm has... The file that's opened is index.php in the root of the project, but in the project tree on the left, index.php in class/ is highlighted. VSCode highlights the correct file whenever it comes into focus. It makes it much easier to follow (the tutorial).

    • @ApplicableProgramming
      @ApplicableProgramming  2 місяці тому

      yeah, that is a on-off feature you can control in storm as well. I have it on by default, but in toturials it just jumps all over the place, and it is difficult to follow, so I turned it off.

  • @akhilakrishna6253
    @akhilakrishna6253 5 місяців тому +1

    Sir I have a doubt. Can you share your mailid?

  • @Engazan
    @Engazan 2 роки тому +2

    9:48, hmm i m php dev for 4 years and in my opinion every method that not using "$this" should be static, idk why u telling oposit it does not make any sense to me, and no Static method are not only for singletons ..., and yup static is even faster ( micro optimization ) its like concationation where " 'test' . $value " is frw times slower then "test $value", yea its not problem in most cases but when u have masive App that every MS count its better
    26:47 your IDE is set to php 7.4 :/ you should use its power :)

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

      I thought long about your comment, and I think I understand your point. If I understand you correctly, your argument is that Static methods are faster and thus should be used when the method is not referring to $this?
      I've never heard of that recommendation to be honest, so.. I really do not have any particular opinion about it. I've never heard of a project that requires that level of optimisation, especially at the cost of "locking your self in" in using the static methods vs creating the object properly. Why would a controller not use full object and remove/complicate the inheritance and other things that follow the Singleton?
      Concatenation example is the same argument about single vs double quotes around strings, spaces vs tabs.... totally pointless in my opinion, as there are dozen things that can be done on any project that can impact the performance significantly more then using quotes or micro optimising method calls (especially if it goes against recommended practice).
      I am somehow just not convinced that it is important thing to consider... I knew the guy who argued that his code written in one line is faster than ours written in multiple lines. Maybe, but at what price and cost? Where will you pay that price in half a millisecond, when noone else can work on that project? Nah... I would rather focus on the areas that have more impact on the code and maybe the project itself, and code readability is definitively something that can cost/save more money in the project lifetime.
      About PHP8, I keep it intentionally on the older version of php storm and php version, as principles should also apply and work for people stuck on a bit older projects.
      Or have I misunderstood your point?

    • @Engazan
      @Engazan 2 роки тому +1

      @@ApplicableProgrammingyes its faster With JiT, but speed is not main reason
      Let think this way u open Class and look at the metód when u see “static” u r going to use it instantly
      But when u dont see static u scrolling to constructor and thinking how u gonna fake it to make new instance, then u scroll again to see if class is not abstract if not u need look for extends if u saw “parent” in constructor and thinking how u honna fake it again
      So time consumed making new instance and figuring out what u need is so big
      And if that code isnt your then its harder

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

      @@Engazan I understand that use case, it makes sense. However, do you really need to look inside the class and method to know what it does? That is where good abstraction and api should help. I mean, when you use some Laravel library, or Httpful or Imagine or Swift mailer, do you look into the methods to see how to use the library? I don't remember last time I opened some library to see how to use it. And every of our classes should (of course, in ideal world) be easy to use enough that you do not have to look inside.
      I get your point, it is easier to see what is going on when you do not have to follow the code too much, but that limits the toolset we have. I am all about simple code, but one could read your comment as "do not use inheritance, because then you do not understand how it works in constructor when you open the class", and I am sure inheritance has a lot of benefits that overcome reading the constructor. Constructing "difficult" objects could be solved with factories, not by removing basic elements of OOP is based on, like the inheritance.
      I think I mentioned in this example as well (or was it in another course), but controller could have a BaseController, and that could be used to share functionality and application state between different controllers, and that instantly kicks out the static methods.
      I do see the benefit of using Static methods for helper classes though, say simple validation or string conversion or things like that class is basically a collection of functions, but not for controllers that could benefit a lot from inheritance.

    • @Engazan
      @Engazan 2 роки тому +1

      @@ApplicableProgramming Yup inheritance is good, but i mean something like this ( frontend example ) u have Class named Colors where y have method “getTextColor” and u need call it just once so static is faster, easyer to write and doesnt break any pattern
      (new Colors())->getTextColor()
      Vs
      Colors::getTextColor()
      But basicly it can be always helper, but its not writed rule to avoid static methods in classes

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

      @@Engazan For helper classes/methods I agree completely, static methods even indicate as you said that they probably have no other dependencies and do not change state of any object.

  • @hexi3064
    @hexi3064 2 роки тому +1

    There is no such word as 'algorythm', use the correct version 'algorithm'.

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

      Thanks for pointing that out. English is my fourth language, so I do make some silly mistakes from time to time :)

    • @hexi3064
      @hexi3064 2 роки тому +1

      Wow, I'm impressed in that case because you're speaking quite decently. By the way, thank you for the video! ;)

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

      @@hexi3064 thanks, i moved a lot :)
      Do you have some code you would like reviewed? (You can write something during the weekend and send it over)

    • @hexi3064
      @hexi3064 2 роки тому +1

      @@ApplicableProgramming I'm currently studying so my time is limited but why not give it a try! I will write a simple OOP project and send you to the code review (in a week or two). And I have to admit, it's really kind of you to do it :)

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

      @@hexi3064 Sure, it is honestly easier to review code then to write it :D And probably more useful to others as well. I am also studying now, so I know how it goes :)
      Just hit me up when you have something, either here or on the discord/facebook (links are on the channel page)