- Singleton (Cell Nucleus):
class Nucleus {
private static instance: Nucleus;
private constructor() {}
static getInstance(): Nucleus {
if (!Nucleus.instance) {
Nucleus.instance = new Nucleus();
}
return Nucleus.instance;
}
controlCell(): void {
console.log("Controlling cell activities");
}
}
- Factory Method (Ribosomes):
abstract class Ribosome {
abstract synthesizeProtein(mRNA: string): Protein;
}
class Protein {}
class EukaryoticRibosome extends Ribosome {
synthesizeProtein(mRNA: string): Protein {
return new Protein();
}
}
- Abstract Factory (Cell Differentiation):
interface CellFactory {
createNucleus(): Nucleus;
createMitochondria(): Mitochondria;
}
class StemCell implements CellFactory {
createNucleus(): Nucleus { return new Nucleus(); }
createMitochondria(): Mitochondria { return new Mitochondria(); }
}
class NeuronCell implements CellFactory {
createNucleus(): Nucleus { return new NeuronNucleus(); }
createMitochondria(): Mitochondria { return new NeuronMitochondria(); }
}
- Builder (Protein Synthesis):
class ProteinBuilder {
private sequence: string = '';
addAminoAcid(aa: string): this {
this.sequence += aa;
return this;
}
build(): Protein {
return new Protein(this.sequence);
}
}
- Prototype (Cell Division):
class Cell implements Cloneable {
constructor(public dna: string) {}
clone(): Cell {
return new Cell(this.dna);
}
mutate(): void {
// Implement mutation logic
}
}
- Adapter (Enzyme-Substrate Interactions):
interface Substrate { react(): void; }
class Glucose implements Substrate {
react(): void { console.log("Glucose reacting"); }
}
class Enzyme {
process(substrate: Substrate): void {
substrate.react();
}
}
- Bridge (Signal Transduction):
interface SignalReceiver {
receiveSignal(signal: string): void;
}
class CellResponse {
respond(): void {
console.log("Cell responding to signal");
}
}
class SignalTransducer implements SignalReceiver {
constructor(private response: CellResponse) {}
receiveSignal(signal: string): void {
console.log(`Received signal: ${signal}`);
this.response.respond();
}
}
- Composite (Multicellular Organisms):
abstract class BiologicalUnit {
abstract function(): void;
}
class Cell extends BiologicalUnit {
function(): void {
console.log("Cell functioning");
}
}
class Organ extends BiologicalUnit {
private parts: BiologicalUnit[] = [];
add(part: BiologicalUnit): void {
this.parts.push(part);
}
function(): void {
this.parts.forEach(part => part.function());
}
}
- Decorator (Post-translational Modifications):
interface Protein {
function(): void;
}
class BaseProtein implements Protein {
function(): void {
console.log("Base protein function");
}
}
class Phosphorylation implements Protein {
constructor(private protein: Protein) {}
function(): void {
this.protein.function();
console.log("Added phosphate group");
}
}
- Facade (Cell Membrane):
class CellMembrane {
transportNutrients(): void {
console.log("Transporting nutrients");
}
signalReception(): void {
console.log("Receiving signals");
}
wasteRemoval(): void {
console.log("Removing waste");
}
}
- Flyweight (tRNA Usage):
class tRNA {
constructor(public anticodon: string) {}
}
class tRNAPool {
private tRNAs: {[key: string]: tRNA} = {};
gettRNA(anticodon: string): tRNA {
if (!this.tRNAs[anticodon]) {
this.tRNAs[anticodon] = new tRNA(anticodon);
}
return this.tRNAs[anticodon];
}
}
- Proxy (Nuclear Pore Complex):
interface NuclearAccess {
enterNucleus(molecule: Molecule): void;
}
class Nucleus implements NuclearAccess {
enterNucleus(molecule: Molecule): void {
console.log("Molecule entered nucleus");
}
}
class NuclearPoreComplex implements NuclearAccess {
constructor(private nucleus: Nucleus) {}
enterNucleus(molecule: Molecule): void {
if (this.checkMolecule(molecule)) {
this.nucleus.enterNucleus(molecule);
}
}
private checkMolecule(molecule: Molecule): boolean {
return true; // Simplified check
}
}
- Chain of Responsibility (Signal Cascades):
abstract class SignalProtein {
protected next: SignalProtein | null = null;
setNext(protein: SignalProtein): SignalProtein {
this.next = protein;
return protein;
}
abstract handle(signal: string): void;
}
class KinaseA extends SignalProtein {
handle(signal: string): void {
if (signal === "hormoneA") {
console.log("KinaseA activated");
} else if (this.next) {
this.next.handle(signal);
}
}
}
- Command (Hormones):
interface CellCommand {
execute(): void;
}
class InsulinCommand implements CellCommand {
constructor(private cell: Cell) {}
execute(): void {
this.cell.absorbGlucose();
}
}
class Hormone {
constructor(private command: CellCommand) {}
bind(): void {
this.command.execute();
}
}
- Iterator (DNA Replication):
class DNA {
constructor(private sequence: string) {}
[Symbol.iterator]() {
let index = 0;
return {
next: () => {
if (index < this.sequence.length) {
return { value: this.sequence[index++], done: false };
} else {
return { done: true };
}
}
};
}
}
- Mediator (Endocrine System):
class Hormone {
constructor(public name: string) {}
}
class EndocrineSystem {
notify(organ: Organ, hormone: Hormone): void {
console.log(`${organ.name} notified of ${hormone.name}`);
}
}
class Organ {
constructor(public name: string, private system: EndocrineSystem) {}
receiveSignal(hormone: Hormone): void {
this.system.notify(this, hormone);
}
}
- Memento (Gene Silencing):
class GeneExpression {
constructor(private state: boolean = true) {}
silence(): void { this.state = false; }
express(): void { this.state = true; }
saveState(): GeneMemento {
return new GeneMemento(this.state);
}
restoreState(memento: GeneMemento): void {
this.state = memento.getState();
}
}
class GeneMemento {
constructor(private state: boolean) {}
getState(): boolean { return this.state; }
}
- Observer (Gene Regulation):
interface GeneObserver {
update(signal: string): void;
}
class Gene implements GeneObserver {
update(signal: string): void {
console.log(`Gene expression changed due to ${signal}`);
}
}
class TranscriptionFactor {
private observers: GeneObserver[] = [];
addObserver(observer: GeneObserver): void {
this.observers.push(observer);
}
notifyObservers(signal: string): void {
this.observers.forEach(observer => observer.update(signal));
}
}
- State (Cell Cycle Phases):
interface CellState {
performAction(cell: Cell): void;
}
class G1Phase implements CellState {
performAction(cell: Cell): void {
console.log("Cell growing");
}
}
class SPhase implements CellState {
performAction(cell: Cell): void {
console.log("DNA replicating");
}
}
class Cell {
private state: CellState;
constructor() {
this.state = new G1Phase();
}
setState(state: CellState): void {
this.state = state;
}
performAction(): void {
this.state.performAction(this);
}
}
- Strategy (Alternative Splicing):
interface SplicingStrategy {
splice(preRNA: string): string;
}
class ExonSkipping implements SplicingStrategy {
splice(preRNA: string): string {
return "Skipped exon version";
}
}
class IntronRetention implements SplicingStrategy {
splice(preRNA: string): string {
return "Retained intron version";
}
}
class Spliceosome {
constructor(private strategy: SplicingStrategy) {}
performSplicing(preRNA: string): string {
return this.strategy.splice(preRNA);
}
}
- Template Method (DNA Replication):
abstract class DNAReplication {
replicate(): void {
this.unwind();
this.primeSynthesis();
this.elongate();
this.terminateAndLigate();
}
protected unwind(): void {
console.log("Unwinding DNA");
}
protected abstract primeSynthesis(): void;
protected abstract elongate(): void;
protected terminateAndLigate(): void {
console.log("Terminating and ligating");
}
}
class LeadingStrandReplication extends DNAReplication {
protected primeSynthesis(): void {
console.log("Single primer synthesis");
}
protected elongate(): void {
console.log("Continuous elongation");
}
}
- Visitor (Immune System Recognition):
interface Cell {
accept(visitor: ImmuneCell): void;
}
class BodyCell implements Cell {
accept(visitor: ImmuneCell): void {
visitor.visit(this);
}
}
interface ImmuneCell {
visit(cell: BodyCell): void;
}
class TCell implements ImmuneCell {
visit(cell: BodyCell): void {
console.log("T Cell checking for antigens");
}
}