Skip to content

Instantly share code, notes, and snippets.

View unclexo's full-sized avatar
🏠
Working from home

Abu Jobaer unclexo

🏠
Working from home
View GitHub Profile
@unclexo
unclexo / dip.ts
Created May 26, 2023 07:30
The Dependency-Inversion Principle TypeScript code example
type PostData = {
userId: number,
message: string,
}
interface Postable {
/**
* Publishes post
*
* @param {PostData} data
@unclexo
unclexo / dip.php
Created May 26, 2023 07:30
The Dependency-Inversion Principle PHP code example
<?php
interface Postable
{
/**
* Publishes post
*
* @param array<string, mixed> data
* @return mixed
*/
@unclexo
unclexo / isp.ts
Created May 23, 2023 16:38
The Interface Segregation Principle PHP code example
type NotifyingData = {
some: string,
more: string,
}
interface Notifiable {
/**
* Sends notifications
*
* @param {NotifyingData} data
@unclexo
unclexo / isp.php
Created May 23, 2023 15:55
The Interface Segregation Principle PHP code example
<?php
interface Notifiable
{
/**
* Send notifications
*
* @param array $data
* @return void
*/
@unclexo
unclexo / lsp.php
Created May 23, 2023 09:48
The Liskov Substitution Principle PHP code example
<?php
abstract class Product
{
private string $filePath;
public function __construct(string $filePath)
{
$this->filePath = $filePath;
}
@unclexo
unclexo / lsp.ts
Created May 23, 2023 09:39
The Liskov Substitution Principle TypeScript code example
import express, { Router, Request, Response } from 'express'
import fs from 'fs';
import path from 'path';
abstract class Product {
private filePath: string;
private response: Response;
constructor(filePath: string, response: Response) {
@unclexo
unclexo / ocp.ts
Created May 20, 2023 12:12
The Open-Closed Principle TypeScript example
abstract class AbstractProduct {
private title: string;
constructor(title: string) {
this.title = title;
}
public getTitle(): string {
return this.title;
}
@unclexo
unclexo / ocp.php
Last active May 20, 2023 12:10
The Open-Closed Principle PHP code example
<?php
abstract class AbstractProduct
{
private string $title;
public function getTitle(): string
{
return $this->title;
}
@unclexo
unclexo / ChainOfResponsibility.java
Last active February 22, 2023 17:36
Chain of Responsibility pattern JAVA code example
class Job {
private String details;
public Job(String details) {
this.details = details;
}
public String requirements() {
return this.details;
}
@unclexo
unclexo / ChainOfResponsibility.php
Created February 22, 2023 17:27
Chain of Responsibility pattern PHP code example
<?php
class Job {
private $details;
public function __construct($details) {
$this->details = $details;
}
public function requirements() {