Skip to content

Instantly share code, notes, and snippets.

Avatar
😉
Focusing

Ali Nazari AliN11

😉
Focusing
View GitHub Profile
@AliN11
AliN11 / designpatterns-builder.ts
Created Apr 4, 2021
Builder Design Pattern with Typescript
View designpatterns-builder.ts
interface QueryBuilder {
table(table): QueryBuilder;
select(cols): QueryBuilder;
limit(value: Number): QueryBuilder;
where(col, value): QueryBuilder;
getQuery(): String;
/* +100 Other SQL Methods */
}
View designpatterns-abstract-factory.ts
interface Tablet {
switchOn();
}
interface Smartphone {
switchOn();
ring();
}
class SamsungSmartphone implements Smartphone {
View designpatterns-factory-method.ts
interface Vehicle {
setMode(mode);
move();
}
abstract class Delivery {
public abstract makeVehicle(): Vehicle;
public handle() {
const vehicle = this.makeVehicle();
View typescript-open-closed-principle.ts
interface LanguageInterface {
sayHello(): string;
}
class Persian implements LanguageInterface {
public sayHello(): string {
return 'درود';
}
}
@AliN11
AliN11 / typescript-dependency-injection.ts
Created Sep 15, 2019
Typescript Dependency Injection
View typescript-dependency-injection.ts
interface Wheel {}
interface Engine {}
class Car {
private wheel: Wheel;
private engine: Engine;
public constructor(wheel: Wheel, engine: Engine) {
this.wheel = wheel;
this.engine = engine;
@AliN11
AliN11 / typescript-generics.ts
Created Aug 15, 2019
Typescript Generics in classes
View typescript-generics.ts
class Queue<T> {
private data: T[] = [];
push(item: T) {
this.data.push(item);
}
pop(): T | undefined {
return this.data.shift();
}
View typescript-accessors.ts
class User {
private rawUsername: string;
get userName(): string {
return "The fullname is: " + this.rawUsername;
}
set userName(newName: string) {
if (newName.length > 10) {
newName = newName.substr(0, 10);
View typescript-simple-class.ts
class Person {
name: string;
constructor(name: string) {
this.name = name;
}
sayHello(): string {
return `Hello ${this.name}, Welcome to Ditty.ir`;
}
View javascript-push-object-into-local-storage.js
let person = {
name: 'Bastian',
lastname: 'Schweinsteiger'
};
person = JSON.stringify(person);
localStorage.setItem('user', person);
View javascript-hoisting.js
// These two lines:
console.log(y); // undefined
y = "Street";
// are interpreted as:
var y;
console.log(y); // undefined
y = "Street";