When Objects Aren't Enough
– www.tonysm.com - submitted by Tony Messias
Tony Messias been looking up resources on the roots of Object-Oriented Programming. He shares some very interesting ideas.
Read more [www.tonysm.com]
Posts tagged with oop
– www.tonysm.com - submitted by Tony Messias
Tony Messias been looking up resources on the roots of Object-Oriented Programming. He shares some very interesting ideas.
Read more [www.tonysm.com]
Here's an entire chapter taken from Front Line PHP, a course on building moderns apps with PHP 8
Read more [front-line-php.com]
Join 9,500+ smart developers
Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
Jason McCreary makes the case for using traits over reaching for inheritance.
Read more [jasonmccreary.me]
Geepaw Hill explains a way to avoid demeter violations.
Read more [www.geepawhill.org]
Larry Garfield has some interesting thoughts on how PHP can be improved.
Read more [hive.blog]
– liamhammett.com - submitted by Liam Hammett
A static constructor is just a method the developer can define on a class which can be used to initialise any static properties, or to perform any actions that only need to be performed only once for the given class. The method is only called once as the class is needed.
Read more [liamhammett.com]
Thanks to the improved type variance in PHP 7.4, the `self` return type hint is now safe to use in a class that you expect to be overridden (happens a lot in the packages we create)
— Freek Van der Herten (@freekmurze) December 3, 2019
Demo: https://t.co/7vRTaOwRhD
RFC: https://t.co/1RpnFIjlKC#php pic.twitter.com/SfAaxRDt4m
Read more [twitter.com]
A cool talk by John Cinnamond, on how you can create a pure OO language and why you shouldn't do that.
In an older but still relevant post, Jeff Atwood shares why you shouldn't use boolean parameters and how this translation to UI.
Read more [blog.codinghorror.com]
Here's a talk by Mark Seeman that explains the differences between object oriented and functional programming.
– dcsg.me
Daniel Gomes, a developer at Teamleader, explains a potential problem when cloning object in PHP.
As you know, PHP has a well-known clone keyword that shallow copy all of the object’s properties. So under the hood what it does is to create a new Object with the exact same values of that object properties – unless you change its behavior by implementing the clone() function in your class.
Read more [dcsg.me]
In another cool blogpost, Matthias Noback explains a few best practices around newing up objects, illustrated with some great examples.
Consider the following rule: "When you create an object, it should be complete, consistent and valid in one go." It is derived from the more general principle that it should not be possible for an object to exist in an inconsistent state. I think this is a very important rule, one that will gradually lead everyone from the swamps of those dreaded "anemic" domain models. However, the question still remains: what does all of this mean?
Read more [matthiasnoback.nl]
Mark Baker, serial conference speaker and creator of the PhpSpreadsheet package shares some thoughts on how to create private classes using anonymous classes.
I’ve written before about the benefits of using PHP’s Anonymous Classes for test doubles; but Anonymous Classes also have potential usecases within production code as well. In this article I’m going to describe one such usecase that can be particularly useful within libraries, and that is replicating the access of Package Private (in Java), or Protected Internal Classes (as per C#).
Read more [markbakeruk.net]
In a new post Uncle Bob explains that you shouldn't have to choose between functional programming and object orientation.
In this blog I will make the case that while OO and FP are orthogonal, they are not mutually exclusive. That a good functional program can (and should) be object oriented. And that a good object oriented program can (and should) be functional. But to accomplish this goal we are going to have to define our terms very carefully.
http://blog.cleancoder.com/uncle-bob/2018/04/13/FPvsOO.html
Caleb Porzio, co-presenter of the Twenty Percent Time podcast, published a new article on the Tightenco blog. This time he guides us through a nice use case for extending Eloquent models.
Let’s explore another alternative that can be used as a stand-in for repetitive where statements and local scopes. This technique involves creating new Eloquent models that extend other models. By extending another model, you inherit the full functionality of the parent model, while retaining the ability to add custom methods, scopes, event listeners, etc. This is commonly referred to as “Single Table Inheritance,” but I prefer to just call it “Model Inheritance”.
Josh Justice gives some solid advice on how to pick the right language for your next projects.
So to ask the question “should I use an OO or FP language (or style)” is to skip several steps. I think a better series of questions are: First, what properties would be beneficial for your application to have: concurrency? Immutability? Encapsulation? There are a lot of things you won’t know about your application at first, but you can at least know if it will be a backend app, JavaScript browser app, or native mobile app; if it will be CPU-bound or IO-bound; and if it will process data inputted by humans or automatically generated by machines. All of those factors can influence which properties you need.Once that’s decided, the next question is, in a given language, are those properties guaranteed, easy, difficult, or not realistically achievable?
http://codingitwrong.com/2017/07/27/language-features-and-code-properties.html
This a video of a great lecture Bob Martin gave a couple of years ago. Even if you know the solid principles it's great to hear him talk about the origin of Objective C, what makes object orientation (not) special and so much more.
In a new post on his blog Adam Wathan explains his thinking on the meaning of having a method on an object.
The fundamental misunderstanding here is thinking that methods are things an object can do.If you believe that the methods on an object represent the abilities of that object, then of course an Announcement having a broadcast() method sounds silly.
But what if methods weren't the things an object could do? What if they were the things you could do with that object?
If methods were the actions an object afforded us, then it would make perfect sense to be able to broadcast() an Announcement, wouldn't it?
https://adamwathan.me/2017/01/24/methods-are-affordances-not-abilities/
I love those conversational posts written by Uncle Bob. This time he responds to an article by Luciano Mammino who is saying goodbye to OO programming. Uncle Bob's conclusion:
We need to choose a language, or two, or three. A small set of simple frameworks. Build up our tools. Solidify our processes. And become a goddam profession.
Amen to that! Read the entire article on the Cleancoder blog.
Stoimen Popov advises not to call __destruct() manually.
The important thing to note is that you shouldn’t call the destructor of an object explicitly! Not because it will throw an fatal error, but simply because it won’t destroy the object.
http://www.stoimen.com/blog/2011/11/14/php-dont-call-the-destructor-explicitly/