Posts

  • Laravel setup alias and service provider in a package

    Hello folks. This article is just a brief explanation on how you can create new run-time alias and load service provider within your laravel package. If you want to load other service provider from the package you have to use this command inside the register method if your service provider:

  • SOLID Design principles and Php: Liskov substitution

    Hello everybody, today we talk about the third letter (L) of SOLID principles: Liskov substitution. This principle has a mathematical definition pretty hard to understand, but in practise it says: every time you create a subclass of a superclass that subclass should be substitutable in every place where the original class took place. Let’s dig in with an example. Imagine we create a player class. ```php Class player { public function play($file) { // play the file… }

    }

  • SOLID Design principles and Php: Open closed

    In this article we talk about the O in SOLID principles: Open closed. The Open closed principle says that: a class should be open for extension but closed for modification, what that means? Well, in practise when you make a class you could expand it for adding new features but not modify it for changing his beahvior, instead you should separate the extensible behavior behind an interface and flip the dependencies. What that means? I’ll drive into that with an example. Let’s say we are writing a business application to handle building information in a certain country. Let’s create a class to handle small apartments:

  • SOLID Design principles and Php: Single responsability

    Hello guys, this is the first article (of 5) About SOLID design principles. Solid design principles was written by Uncle Bob Martin with the objective to help building quality code. But how can you say that you have written good code? You could say: when the code works its good code, but in fact that’s not; in fact the biggest quality of software are that it’s easy to replicate and easy to modify. When you have fear to change a certain in code (because something may break) than that’s bad code; code should be easy to modify! All thoose principles are based on making code less coupled as possible to allow easy modification and can be summarized in one single phrase: “Program the interface!”. As i first approached SOLID principles they was looking a bit complicated and overwhelming, but after i understood them they changed the way i make software in a better way. If you are a developer in my opinion you should know thoose principles: belive me or not they will change your life! Let’s talk about Single responsability. The principle of single responsability says: “A class should have one and only one reason to change”. So when you build a class you should ask yourself: shall this class do that? Or should this class change in order to modify this beaviour? Let’s dig into that with an example. A commom approach of programmer that use MVC pattern is that they tend to put all the business logic in the controller and the data acces into the model. The role of the controller is not to hold the application logic but instead to catch the http request data and to respond with some other data, the controller should be totally ignorant about what we do with the data. Here is a classical example(Using Laravel) that doest not respect Single responsability principle:

  • Active Record Design pattern

    Hello folks, in this article i’ll briefly explain the Active record design pattern. Active record is one of the data access pattern which helps you to map your domain model (Object) into Relational Database. Basically with active record, every istance of your class correspond to one row in a table of the database (one to one relationship). The active record basic usage consist in extending the abstract active record class from your model class. With this pattern the biggest advantage it’s simplicity, in fact this pattern is used in many ORM, for example Laravel ORM Eloquent, Yii ORM, FuelPHP ORM or Ruby on Rails ORM. I’ll show you how that works with a simple example. I’ve created a class that implement the active record pattern(keep in mind it’s really simple and to be used well need to be expanded). As i’m used to do i’ll explain that by examples, now imagine we have the MobilePhone Class, which have the following attributes:

subscribe via RSS