DEV Community

Cover image for SOLID PRINCIPLES: To start with Object-oriented programming

SOLID PRINCIPLES: To start with Object-oriented programming

Emma Ham on September 17, 2019

Hi everyone, today I would like to discuss about something solid. solid? Of course, no! Not that solid. wait... ah maybe exactly that solid! I w...
Collapse
 
pedro00dk profile image
Pedro Henrique

Cool article, I didn't remember these definitions anymore, even though I use then when codding.
Just a detail, the square-rectangle diagram should be the opposite, as squares have more constraints, so they are a subset of rectangles.

Collapse
 
davjvo profile image
Davmi Jose Valdez Ogando

SOLID can be tricky to remember every single component, or at least for me.

Like the simple explanation of this post, although when that question comes simply say yes, modern common architectures all implement SOLID principle, so if you implement any architecture step by step you are for sure following SOLID principle

Collapse
 
corsari profile image
corsari • Edited

Hello Emma, thank you for this synthesis and summary altogether.

Do you kindly have a link to VERY BASIC PHP OOP tutorial ,

I mean a MINIMAL app, like a TODO list or similar, where the TUTOR applies the OOP and its S.O.L.I.D. principles so much. I mean such a kind of over-use of classes as a stretch,

as the word say ---> for tutoring the student

also (and mainly) to show how classes passes tasks one to each other

Unfortunately if you google for PHP OOP, you are flooded with thousands of guides and tutorials that are really silly

They teaches you the dictionary of PHP classes and their grammatical and magic methods ... but NO a SINGLE ONE of them shows a practical implementation or (and MAINLY) the interaction between the classes.

OOP is abstraction and tutorials that add abstraction to abstraction ... are really worse...

... the best idea would be a tutorial where the supposed above TODO list or basic app, as in your examples in this great article, is FIRST written in the classical old style procedural way

then the SAME identical is realized with as many classes as possible (either "excessive" use of classes, the idea there is to show how to make them interact with each other the proper way)

Thank you for any link or , even more, if you may think to write one :-) since I like so much your way to explain ;_)

P.S. I suppose it could become really referenced and popular

Collapse
 
jcmarquet profile image
Jean-Christophe MARQUET

I spend so much time talking about SOLID principles to junior members of the team but I don't seem to be able to remember what principle is what letter. It's kind of ridiculous really.

This article is now in my favorites and I intend to use it when explaining the gains of these principles. It's very simple and I like the before/after approach. Good job and thanx !

Collapse
 
vlasales profile image
Vlastimil Pospichal

SRP:

<?php declare(strict_types=1);

class Book implements JsonSerializable {
    private $author;

    function __construct(string $author) {
        $this->author = $author;
    }

    public function getAuthor() {
        return $this->author;
    }

    public function jsonSerialize() {
        return $this->getAuthor();
    }

}

$book = new Book('Author');
echo json_encode($book);
Collapse
 
bilalisz profile image
Muhammad Bilal

Hi dear,,,
You know, this is too useful for me I'm a fresh graduated and now turn for developing, but a lot of problems i face, can you helf me for more like that's concept for development,would you give me your social media address

Collapse
 
ham8821 profile image
Emma Ham

Hi there, you can check out my linked in by clicking the icon in my profile!

Collapse
 
xalitech profile image
Xali Tech

Very good write up on design principles, here are five core object-oriented principles SOLID, xalitech.com/solid-principles-of-o...

Collapse
 
kehinde_issa profile image
Issa kehinde

Fantastic write-up! only that in maths a square is a subset of a rectangle.

Collapse
 
evrtrabajo profile image
Emmanuel Valverde Ramos
Collapse
 
rohullahayobi profile image
R.A.

So everything here is about to always construct classes for only one purpose and functionality.
Cool article!