{
    "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen",
    "locale": "en",
    "title": "Programming paradigms and design patterns · DeLaParra Services",
    "description": "A practical guide to object-oriented, functional, declarative, event-driven and concurrent programming, and the design patterns you’ll most commonly encounter in Laravel and JavaScript.",
    "alternates": {
        "en": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen",
        "nl": "https://delaparra-services.nl/nl/handleidingen/programmeerstijlen-en-ontwerppatronen"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.csv",
        "md": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.md",
        "json": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.json",
        "zip": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.zip",
        "pdf": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.csv",
            "encodingFormat": "text/csv",
            "name": "programmeerstijlen-en-ontwerppatronen.csv"
        },
        {
            "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.json",
            "encodingFormat": "application/json",
            "name": "programmeerstijlen-en-ontwerppatronen.json"
        },
        {
            "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.md",
            "encodingFormat": "text/markdown",
            "name": "programmeerstijlen-en-ontwerppatronen.md"
        },
        {
            "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.pdf",
            "encodingFormat": "application/pdf",
            "name": "programmeerstijlen-en-ontwerppatronen.pdf"
        },
        {
            "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.zip",
            "encodingFormat": "application/zip",
            "name": "programmeerstijlen-en-ontwerppatronen.zip"
        }
    ],
    "markdown": "# Programming styles and design patterns\n\nYour AI assistant uses terms such as ‘functional’, ‘dependency injection’ or ‘observer pattern’. You don’t need to be able to programme them yourself, but if you know what they mean, you’ll be better placed to judge whether its suggestion is appropriate.\n\n## Programming styles (paradigms)\n\n| Style | Essence | Where you see it |\n|---|---|---|\n| **Imperative / procedural** | Explaining *how* to do something step by step | Scripts, older PHP |\n| **Declarative** | Say *what* you want, not how | SQL, HTML, CSS, Terraform, React components |\n| **Object-oriented (OOP)** | Data and behaviour combined in objects (classes) | Laravel models and controllers, Java |\n| **Functional (FP)** | Functions without side effects; do not modify data, but create new data | `map`/`filter`/`reduce`, Laravel Collections, React |\n| **Event-driven** | Code responds to events | Laravel Events and Listeners, JavaScript clicks, webhooks |\n| **Reactive** | Data streams you ‘subscribe’ to | RxJS, live updates |\n| **Concurrent / parallel** | Multiple things at once | Queues, async/await, threads |\n| **Logical / declarative with rules** | Facts and rules; the system finds the solution | Prolog, rule engines |\n| **Aspect-oriented programming (AOP)** | Weaving general concerns (logging, permissions) ‘around’ the code | Middleware is similar to this |\n\nIn practice, modern code combines several styles. A Laravel app is object-oriented, uses functional Collections, declarative migrations and event-driven queues.\n\n## Key concepts\n\n- **Encapsulation:** an object hides its internal workings and provides only proper methods.\n- **Inheritance:** a class inherits behaviour from another. Use sparingly; composition is often better.\n- **Polymorphism:** different objects respond to the same call in their own way.\n- **Pure function:** same input, always the same output, no side effects. Easy to test.\n- **Immutability:** You don’t change the data; you create a new version.\n- **Side effects:** anything that alters a function outside itself (database, file, email).\n- **Callback / higher-order function:** a function that you pass to another function.\n- **Race condition / deadlock:** problems that arise when things happen simultaneously (see the **concurrency-pitfalls** skill).\n\n## Design patterns you often come across\n\n| Pattern | At a glance | Example in Laravel/JS |\n|---|---|---|\n| **Factory** | A place that creates objects for you | Model factories for test data |\n| **Builder** | Building a query step by step | The query builder: `->where()->orderBy()->get()` |\n| **Singleton** | Exactly one instance | `app()->singleton(...)` in the service container |\n| **Adapter** | Adapting items with a slightly different shape | Email and storage drivers (S3, local) |\n| **Facade** | A simple front-end for something complex | `Cache::`, `Log::`, `Storage::` |\n| **Decorator** | Adding behaviour without modifying the original | Middleware, caching around a service |\n| **Proxy** | Intermediary that manages access | Lazy loading of relationships |\n| **Observer** | Letting others know that something has happened | Model, observers, events, `addEventListener` |\n| **Strategy** | Interchangeable approaches behind a single interface | Various payment or delivery methods |\n| **Command** | A command as an object | Queued jobs, Artisan commands |\n| **Chain of responsibility** | A request passes through a series of processors | The middleware pipeline |\n| **Iterator** | Step by step through a collection | Collections, `foreach`, generators |\n| **Template method** | Fixed step-by-step plan, with details to be filled in | Base classes with overridable methods |\n| **Composite** | Tree structure of identical components | Menus, React components |\n| **Abstract factory** | Creating families of related objects | Themes or drivers per platform |\n| **Prototype** | Creating a new object by copying an existing one | `$model->replicate()`, JS prototypes |\n\n**Dependency injection:** a class receives what it needs from an external source, rather than creating it itself. Laravel’s service container does this automatically when you request a class in your constructor. This makes testing much easier.\n\n## When a pattern is not required\n\nPatterns are tools, not an end in themselves. Is your assistant proposing three layers of interfaces for a simple function? Ask: *“Can this be done more simply, and what do we gain from this pattern?”* Simple code that the team understands is usually better.\n\n## Need help?\n\nIt’s best to make major design decisions before you start building. At OpenSpec**\n\n## Skills\n\n- [Architecture Patterns] (/nl/skills/architecture-patterns)\n- [Clean Code Principles] (/nl/skills/clean-code-principles)\n- [Spatie Laravel & PHP Guidelines] (/nl/skills/spatie-laravel-php)\n- [Cloud Design Patterns] (/nl/skills/cloud-design-patterns)\n- [CQRS Implementation] (/nl/skills/cqrs-implementation)\n- [Microservices Patterns] (/nl/skills/microservices-patterns)\n- [Concurrency pitfalls] (/nl/skills/concurrency-pitfalls)\n\n## Related services\n\n- [OpenSpec](/services#service-04)\n- [Maatwerk software en webapplicaties] (/nl/services#service-03)\n- [Beoordeling van AI-code] (/nl/services#service-05)\n\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "TechArticle",
                "@id": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen#article",
                "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen",
                "headline": "Programming paradigms and design patterns",
                "description": "A practical guide to object-oriented, functional, declarative, event-driven and concurrent programming, and the design patterns you’ll most commonly encounter in Laravel and JavaScript.",
                "inLanguage": "en",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen#dataset",
                "name": "Programming paradigms and design patterns",
                "description": "A practical guide to object-oriented, functional, declarative, event-driven and concurrent programming, and the design patterns you’ll most commonly encounter in Laravel and JavaScript.",
                "url": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen",
                "identifier": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen#article"
                },
                "publisher": {
                    "@type": "Organization",
                    "name": "DeLaParra Services",
                    "url": "https://delaparra-services.nl/"
                },
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/manuals#dataset",
                    "name": "Manuals for working on your own app",
                    "url": "https://delaparra-services.nl/manuals"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "programmeerstijlen-en-ontwerppatronen.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.csv",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "programmeerstijlen-en-ontwerppatronen.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.json",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "programmeerstijlen-en-ontwerppatronen.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.md",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "programmeerstijlen-en-ontwerppatronen.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.pdf",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "programmeerstijlen-en-ontwerppatronen.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/manuals/programmeerstijlen-en-ontwerppatronen.zip",
                        "inLanguage": "en"
                    }
                ]
            }
        ]
    }
}