Last active
July 27, 2024 17:45
Revisions
-
louismullie renamed this gist
Jul 27, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
louismullie revised this gist
Jul 27, 2024 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,33 @@ # Cell Biology Patterns ### Summary | Pattern | Cellular Biology Use Case | |---------|---------------------------| | Singleton | Cell Nucleus: Only one nucleus controls the cell's activities, maintaining a single source of genetic information. | | Factory Method | Ribosomes: Produce different proteins based on the mRNA template, acting as a factory for various protein products. | | Abstract Factory | Cell Differentiation: Stem cells differentiate into various types of specialized cells, each with its own set of organelles and functions. | | Builder | Protein Synthesis: Step-by-step assembly of proteins from amino acids, following the instructions in mRNA. | | Prototype | Cell Division: Creation of new cells by duplicating the contents of an existing cell, with slight modifications in daughter cells. | | Adapter | Enzyme-Substrate Interactions: Enzymes adapt to fit different substrates, allowing various molecules to be processed. | | Bridge | Signal Transduction: Separates the reception of external signals from the internal cellular response mechanisms. | | Composite | Multicellular Organisms: Individual cells form tissues, organs, and organ systems, creating a hierarchical structure. | | Decorator | Post-translational Modifications: Addition of functional groups to proteins after translation, modifying their function. | | Facade | Cell Membrane: Provides a simplified interface for complex cellular interactions with the external environment. | | Flyweight | tRNA Usage: Reuse of tRNA molecules for efficient translation of multiple mRNA codons. | | Proxy | Nuclear Pore Complex: Controls access to the cell nucleus, acting as a gateway for molecule transport. | | Chain of Responsibility | Signal Cascades: Series of protein interactions in signaling pathways, where each protein activates the next. | | Command | Hormones: Encapsulate instructions for cells to perform specific actions, triggered by receptor binding. | | Iterator | DNA Replication: Systematic traversal of the DNA strand during replication, processing each base pair sequentially. | | Mediator | Endocrine System: Hormones act as mediators, coordinating activities between different organs and tissues. | | Memento | Gene Silencing: Storage of epigenetic marks that can be restored to affect gene expression without changing DNA sequence. | | Observer | Gene Regulation: Transcription factors observe the presence of specific signals to regulate gene expression. | | State | Cell Cycle Phases: Cells exhibit different behaviors and characteristics as they progress through the stages of the cell cycle. | | Strategy | Alternative Splicing: Different exon combinations from the same pre-mRNA can create various protein isoforms. | | Template Method | DNA Replication: Defines the overall process with specific steps (unwinding, priming, elongation) that may vary between leading and lagging strands. | | Visitor | Immune System Recognition: Immune cells 'visit' other cells to check for antigens, applying different responses based on what they find. | ### Singleton (Cell Nucleus) The Singleton pattern ensures that a class has only one instance and provides a global point of access to it. This mirrors the cell nucleus, which is the single control center for cellular activities. Just as a cell has only one nucleus coordinating its functions, the Singleton pattern maintains a single, centralized instance to manage critical resources or control points in a system. -
louismullie revised this gist
Jul 27, 2024 . No changes.There are no files selected for viewing
-
louismullie revised this gist
Jul 27, 2024 . 1 changed file with 89 additions and 23 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ # Cell Biology Patterns ### Singleton (Cell Nucleus) The Singleton pattern ensures that a class has only one instance and provides a global point of access to it. This mirrors the cell nucleus, which is the single control center for cellular activities. Just as a cell has only one nucleus coordinating its functions, the Singleton pattern maintains a single, centralized instance to manage critical resources or control points in a system. ```typescript class Nucleus { private static instance: Nucleus; @@ -17,7 +20,10 @@ class Nucleus { } ``` ### Factory Method (Ribosomes) The Factory Method pattern defines an interface for creating objects but lets subclasses decide which class to instantiate. This is analogous to ribosomes producing different proteins based on mRNA templates. Like ribosomes that can create various proteins following different mRNA instructions, the Factory Method allows for flexible object creation based on varying inputs or conditions. ```typescript abstract class Ribosome { abstract synthesizeProtein(mRNA: string): Protein; @@ -32,7 +38,10 @@ class EukaryoticRibosome extends Ribosome { } ``` ### Abstract Factory (Cell Differentiation) The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. This is similar to how stem cells can differentiate into various specialized cell types, each with its own set of organelles and functions. The pattern allows for the creation of different "families" of objects, just as stem cells can give rise to different families of specialized cells. ```typescript interface CellFactory { createNucleus(): Nucleus; @@ -50,7 +59,10 @@ class NeuronCell implements CellFactory { } ``` ### Builder (Protein Synthesis) The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations. This mirrors protein synthesis, where amino acids are assembled step-by-step following mRNA instructions to create diverse proteins. The Builder pattern, like protein synthesis, allows for the gradual construction of complex objects with potentially different final forms. ```typescript class ProteinBuilder { private sequence: string = ''; @@ -64,7 +76,10 @@ class ProteinBuilder { } ``` ### Prototype (Cell Division) The Prototype pattern creates new objects by copying an existing object, known as the prototype. This is akin to cell division, where a new cell is created by duplicating an existing cell's contents. Just as daughter cells may have slight modifications from the parent cell, the Prototype pattern allows for creating new objects that are similar but not identical to the original. ```typescript class Cell implements Cloneable { constructor(public dna: string) {} @@ -77,7 +92,10 @@ class Cell implements Cloneable { } ``` ### Adapter (Enzyme-Substrate Interactions) The Adapter pattern allows incompatible interfaces to work together. This is similar to how enzymes adapt to fit different substrates, enabling various molecules to be processed. The Adapter pattern, like enzyme-substrate interactions, allows for flexibility in how different components interact, bridging incompatibilities. ```typescript interface Substrate { react(): void; } class Glucose implements Substrate { @@ -91,7 +109,10 @@ class Enzyme { } ``` ### Bridge (Signal Transduction) The Bridge pattern separates an abstraction from its implementation, allowing them to vary independently. This is analogous to signal transduction in cells, where the reception of external signals is separated from the internal cellular response mechanisms. The pattern, like signal transduction, allows for flexibility in how external inputs are processed and responded to internally. ```typescript interface SignalReceiver { receiveSignal(signal: string): void; @@ -112,7 +133,10 @@ class SignalTransducer implements SignalReceiver { } ``` ### Composite (Multicellular Organisms) The Composite pattern composes objects into tree structures to represent part-whole hierarchies, allowing clients to treat individual objects and compositions uniformly. This mirrors the structure of multicellular organisms, where individual cells form tissues, organs, and organ systems in a hierarchical manner. The pattern, like biological organization, allows for complex structures to be built from simpler components. ```typescript abstract class BiologicalUnit { abstract function(): void; @@ -135,7 +159,10 @@ class Organ extends BiologicalUnit { } ``` ### Decorator (Post-translational Modifications) The Decorator pattern attaches additional responsibilities to an object dynamically. This is similar to post-translational modifications in biology, where proteins are modified after translation to alter their function. The Decorator pattern, like these modifications, allows for the flexible enhancement of objects without altering their core structure. ```typescript interface Protein { function(): void; @@ -156,7 +183,10 @@ class Phosphorylation implements Protein { } ``` ### Facade (Cell Membrane) The Facade pattern provides a unified interface to a set of interfaces in a subsystem, simplifying its use. This is analogous to the cell membrane, which provides a simplified interface for complex cellular interactions with the external environment. The Facade pattern, like the cell membrane, encapsulates complex internal workings and presents a simpler interface to the outside world. ```typescript class CellMembrane { transportNutrients(): void { @@ -171,7 +201,10 @@ class CellMembrane { } ``` ### Flyweight (tRNA Usage) The Flyweight pattern uses sharing to support a large number of fine-grained objects efficiently. This is similar to the reuse of tRNA molecules for efficient translation of multiple mRNA codons. The Flyweight pattern, like tRNA usage, allows for the efficient management of a large number of similar small objects by sharing common parts. ```typescript class tRNA { constructor(public anticodon: string) {} @@ -188,7 +221,10 @@ class tRNAPool { } ``` ### Proxy (Nuclear Pore Complex) The Proxy pattern provides a surrogate or placeholder for another object to control access to it. This is akin to the nuclear pore complex, which controls access to the cell nucleus. The Proxy pattern, like the nuclear pore complex, acts as a gatekeeper, managing access to a protected resource or object. ```typescript interface NuclearAccess { enterNucleus(molecule: Molecule): void; @@ -213,7 +249,10 @@ class NuclearPoreComplex implements NuclearAccess { } ``` ### Chain of Responsibility (Signal Cascades) The Chain of Responsibility pattern passes requests along a chain of handlers, with each deciding to process the request or pass it to the next handler. This mirrors signal cascades in cells, where a series of proteins interact, each activating the next in the pathway. The pattern, like cellular signaling cascades, allows for flexible and decoupled processing of requests or signals. ```typescript abstract class SignalProtein { protected next: SignalProtein | null = null; @@ -235,7 +274,10 @@ class KinaseA extends SignalProtein { } ``` ### Command (Hormones) The Command pattern encapsulates a request as an object, allowing for parameterization of clients with queues, requests, and operations. This is analogous to hormones, which encapsulate instructions for cells to perform specific actions. The Command pattern, like hormones, allows for the encapsulation and transmission of actions or instructions. ```typescript interface CellCommand { execute(): void; @@ -256,7 +298,10 @@ class Hormone { } ``` ### Iterator (DNA Replication) The Iterator pattern provides a way to access elements of a collection sequentially without exposing its underlying representation. This is similar to DNA replication, where the DNA strand is systematically traversed and each base pair is processed sequentially. The Iterator pattern, like DNA replication machinery, provides a standardized way to traverse a complex structure. ```typescript class DNA { constructor(private sequence: string) {} @@ -275,7 +320,10 @@ class DNA { } ``` ### Mediator (Endocrine System) The Mediator pattern defines an object that centralizes communication between other objects, reducing their dependencies on each other. This is akin to the endocrine system, where hormones act as mediators coordinating activities between different organs and tissues. The Mediator pattern, like the endocrine system, allows for decoupled communication between components through a central coordinator. ```typescript class Hormone { constructor(public name: string) {} @@ -295,7 +343,10 @@ class Organ { } ``` ### Memento (Gene Silencing) The Memento pattern captures and restores an object's internal state without violating encapsulation. This is similar to gene silencing mechanisms, where epigenetic marks can be stored and restored to affect gene expression without changing the DNA sequence. The Memento pattern, like epigenetic modifications, allows for the preservation and restoration of state information. ```typescript class GeneExpression { constructor(private state: boolean = true) {} @@ -315,7 +366,10 @@ class GeneMemento { } ``` ### Observer (Gene Regulation) The Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified automatically. This mirrors gene regulation, where transcription factors observe the presence of specific signals to regulate gene expression. The Observer pattern, like gene regulatory networks, allows for responsive and coordinated behavior based on state changes. ```typescript interface GeneObserver { update(signal: string): void; @@ -338,7 +392,10 @@ class TranscriptionFactor { } ``` ### State (Cell Cycle Phases) The State pattern allows an object to alter its behavior when its internal state changes, appearing to change its class. This is analogous to the cell cycle, where cells exhibit different behaviors and characteristics as they progress through various phases. The State pattern, like the cell cycle, allows for objects to change their behavior based on internal state transitions. ```typescript interface CellState { performAction(cell: Cell): void; @@ -370,7 +427,10 @@ class Cell { } ``` ### Strategy (Alternative Splicing) The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. This is similar to alternative splicing, where different exon combinations from the same pre-mRNA can create various protein isoforms. The Strategy pattern, like alternative splicing, allows for flexibility in choosing between different implementations or outcomes based on context. ```typescript interface SplicingStrategy { splice(preRNA: string): string; @@ -396,7 +456,10 @@ class Spliceosome { } ``` ### Template Method (DNA Replication): The Template Method pattern defines the skeleton of an algorithm in a method, deferring some steps to subclasses. This mirrors DNA replication, which has a defined overall process with specific steps that may vary between leading and lagging strands. The Template Method pattern, like DNA replication, provides a structured framework while allowing for variations in specific steps. ```typescript abstract class DNAReplication { replicate(): void { @@ -425,7 +488,10 @@ class LeadingStrandReplication extends DNAReplication { } ``` ### Visitor (Immune System Recognition) The Visitor pattern represents an operation to be performed on elements of an object structure, allowing for new operations to be defined without changing the classes of the elements. This is analogous to how immune cells 'visit' other cells to check for antigens, applying different responses based on what they find. The Visitor pattern, like immune system recognition, allows for flexible operations on a set of objects without modifying their core structure. ```typescript interface Cell { accept(visitor: ImmuneCell): void; -
louismullie renamed this gist
Jul 27, 2024 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -446,6 +446,4 @@ class TCell implements ImmuneCell { console.log("T Cell checking for antigens"); } } ``` -
louismullie created this gist
Jul 27, 2024 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,451 @@ ### Cell Biology Patterns 1. Singleton (Cell Nucleus): ```typescript 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"); } } ``` 2. Factory Method (Ribosomes): ```typescript abstract class Ribosome { abstract synthesizeProtein(mRNA: string): Protein; } class Protein {} class EukaryoticRibosome extends Ribosome { synthesizeProtein(mRNA: string): Protein { return new Protein(); } } ``` 3. Abstract Factory (Cell Differentiation): ```typescript 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(); } } ``` 4. Builder (Protein Synthesis): ```typescript class ProteinBuilder { private sequence: string = ''; addAminoAcid(aa: string): this { this.sequence += aa; return this; } build(): Protein { return new Protein(this.sequence); } } ``` 5. Prototype (Cell Division): ```typescript class Cell implements Cloneable { constructor(public dna: string) {} clone(): Cell { return new Cell(this.dna); } mutate(): void { // Implement mutation logic } } ``` 6. Adapter (Enzyme-Substrate Interactions): ```typescript interface Substrate { react(): void; } class Glucose implements Substrate { react(): void { console.log("Glucose reacting"); } } class Enzyme { process(substrate: Substrate): void { substrate.react(); } } ``` 7. Bridge (Signal Transduction): ```typescript 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(); } } ``` 8. Composite (Multicellular Organisms): ```typescript 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()); } } ``` 9. Decorator (Post-translational Modifications): ```typescript 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"); } } ``` 10. Facade (Cell Membrane): ```typescript class CellMembrane { transportNutrients(): void { console.log("Transporting nutrients"); } signalReception(): void { console.log("Receiving signals"); } wasteRemoval(): void { console.log("Removing waste"); } } ``` 11. Flyweight (tRNA Usage): ```typescript 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]; } } ``` 12. Proxy (Nuclear Pore Complex): ```typescript 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 } } ``` 13. Chain of Responsibility (Signal Cascades): ```typescript 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); } } } ``` 14. Command (Hormones): ```typescript 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(); } } ``` 15. Iterator (DNA Replication): ```typescript 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 }; } } }; } } ``` 16. Mediator (Endocrine System): ```typescript 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); } } ``` 17. Memento (Gene Silencing): ```typescript 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; } } ``` 18. Observer (Gene Regulation): ```typescript 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)); } } ``` 19. State (Cell Cycle Phases): ```typescript 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); } } ``` 20. Strategy (Alternative Splicing): ```typescript 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); } } ``` 21. Template Method (DNA Replication): ```typescript 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"); } } ``` 22. Visitor (Immune System Recognition): ```typescript 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"); } } ``` These snippets provide a simplified representation of how each design pattern might be analogous to cellular processes. They are not meant to be scientifically accurate but rather to illustrate the conceptual similarities between software design patterns and biological systems.