Underscore (_) in Scala
What do _._1 and _++_ mean in Scala? _._1 _1 is a method name. Specifically tuples have a method named _1, which returns the first element of the tuple. So _._1 < _._1 means “call the _1 method on both arguments and check whether the first is less than the second”. Example .toList.sortWith(_._1 < _._1) _._1 calls the method _1 on the wildcard parameter _, which gets the first element of a tuple.
"12 Factor App"
What is The Twelve Factor App? The Twelve Factor App a methodology for building modern, scalable, maintainable Software-as-a-Service (SaaS) apps. The Twelve Factor App is a set of principles that describes a way of making software that, when followed, enables companies to create code that can be released reliably, scaled quickly, and maintained in a consistent and predictable manner. Why Do You Need The Twelve Factor App? In the modern era, software is commonly provided as a service: so-called Web Applications or Software as a Service.
Service Discovery
What is a Service Discovery? The service discovery pattern uses a centralized server named “service registry” to maintain a global view of microservice network locations. Microservices update their location in the service registry at fixed intervals. Clients can connect to the service registry and get information about the location of the microservices. There are 2 main service discovery patterns available to implement service discovery for microservices. Client-side service discovery Server-side service discovery Why Do You Need a Service Discovery?
Service Mesh
What is a Service Mesh? A service mesh is a mechanism for managing communications between the various individual services that make up modern applications in a microservice-based system. Why Do You Need a Service Mesh? Once upon a time, programs were developed and deployed as a single application. This traditional approach, called a monolithic architecture, has worked great for simple applications, but becomes a burden as applications become complex and the codebase expands.
Abstract Factory
Also known as Kit Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Explanation Real-world example To create a kingdom we need objects with a common theme. The Elven Kingdom needs Elven King, Elven Castle, and Elven Army, whereas The Orcish Kingdom needs an Orcish King, Orcish Castle, and Orcish Army. There is a dependency between the objects in the kingdom. In plain words
Aggregator Microservices
Intent The user makes a single call to the aggregator service, and the aggregator then calls each relevant microservice. Explanation Real world example Our web marketplace needs information about products and their current inventory. It makes a call to an aggregator service which in turn calls the product information microservice and product inventory microservice returning the combined information. In plain words Aggregator Microservice collects pieces of data from various microservices and returns an aggregate for processing.
API Gateway
Intent Aggregate calls to microservices in a single location, the API Gateway. The user makes a single call to the API Gateway, and the API Gateway then calls each relevant microservice. Explanation With the Microservices pattern, a client may need data from multiple different microservices. If the client called each microservice directly, that could contribute to longer load times, since the client would have to make a network request for each microservice called.
Also known as Given/When/Then Intent Arrange/Act/Assert (AAA) is a pattern for organizing unit tests. It breaks tests down into three clear and distinct steps: Arrange: Perform the setup and initialization required for the test. Act: Take action(s) required for the test. Assert: Verify the outcome(s) of the test. Explanation This pattern has several significant benefits. It creates a clear separation between a test’s setup, operations, and results. This structure makes the code easier to read and understand.
Intent Separate the construction of a complex object from its representation so that the same construction process can create different representations. Explanation Real-world example Imagine a character generator for a role-playing game. The easiest option is to let the computer create the character for you. If you want to manually select the character details like profession, gender, hair color, etc. the character generation becomes a step-by-step process that completes when all the selections are ready.
Intent Callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time. Explanation Real world example We need to be notified after executing task has finished. We pass a callback method for the executor and wait for it to call back on us. In plain words Callback is a method passed to the executor which will be called at defined moment.
Client Session Pattern
Name Client Session pattern Intent Create stateless servers that removes the problem of clustering, as users can switch between servers seamlessly. Makes data more resilient in case of server fail-over. Works well with smaller data sizes. Explanation Real-World Example You’re looking to create a data management app allowing users to send requests to the server to modify and make changes to data stored on their devices. These requests are small in size and the data is individual to each user, negating the need for a large scale database implementation.
Collecting Parameter
Name Collecting Parameter Intent To store the collaborative result of numerous methods within a collection. Explanation Real-world example Within a large corporate building, there exists a global printer queue that is a collection of all the printing jobs that are currently pending. Various floors contain different models of printers, each having a different printing policy. We must construct a program that can continually add appropriate printing jobs to a collection, which is called the collecting parameter.
Collection Pipeline
Intent Collection Pipeline introduces Function Composition and Collection Pipeline, two functional-style patterns that you can combine to iterate collections in your code. In functional programming, it’s common to sequence complex operations through a series of smaller modular functions or operations. The series is called a composition of functions, or a function composition. When a collection of data flows through a function composition, it becomes a collection pipeline. Function Composition and Collection Pipeline are two design patterns frequently used in functional-style programming.
Also known as Composition pattern Intent The functional pattern representing a style of organizing libraries centered around the idea of combining functions. Putting it simply, there is some type T, some functions for constructing “primitive” values of type T, and some “combinators” which can combine values of type T in various ways to build up more complex values of type T. Explanation Real world example In computer science, combinatory logic is used as a simplified model of computation, used in computability theory and proof theory.
Context object
Name / classification Context Object Also known as Context, Encapsulate Context Intent Decouple data from protocol-specific classes and store the scoped data in an object independent of the underlying protocol technology. Explanation Real-world example This application has different layers labelled A, B and C with each extracting specific information from a similar context for further use in the software. Passing down each pieces of information individually would be inefficient, a method to efficiently store and pass information is needed.
Intent The purpose of the Converter pattern is to provide a generic, common way of bidirectional conversion between corresponding types, allowing a clean implementation in which the types do not need to be aware of each other. Moreover, the Converter pattern introduces bidirectional collection mapping, reducing a boilerplate code to minimum. Explanation Real world example In real world applications it is often the case that database layer consists of entities that need to be mapped into DTOs for use on the business logic layer.
Intent CQRS Command Query Responsibility Segregation - Separate the query side from the command side. Class diagram Applicability Use the CQRS pattern when You want to scale the queries and commands independently. You want to use different data models for queries and commands. Useful when dealing with complex domains. You want to use architectures like event sourcing or task based UI. Credits Greg Young - CQRS, Task Based UIs, Event Sourcing agh!
Name / classification Currying Intent Currying decomposes a function that takes multiple arguments into a sequence of functions that each take a single argument. Curried functions are useful since they can be used to create new functions with lower arity to perform more specialised tasks in a concise and readable manner. This is done via partial application. Explanation Real-world example Consider a librarian who wants to populate their library with books.
Data Access Object
Intent Object provides an abstract interface to some type of database or other persistence mechanism. Explanation Real world example There’s a set of customers that need to be persisted to database. Additionally we need the whole set of CRUD (create/read/update/delete) operations so we can operate on customers easily. In plain words DAO is an interface we provide over the base persistence mechanism. Wikipedia says In computer software, a data access object (DAO) is a pattern that provides an abstract interface to some type of database or other persistence mechanism.
Data Bus
Intent Allows send of messages/events between components of an application without them needing to know about each other. They only need to know about the type of the message/event being sent. Explanation Real world example Say you have an app that enables online bookings and participation of events. You want the app to send notifications such as event advertisements to everyone who is an ordinary member of the community or organisation holding the events.
Data Mapper
Intent Data Mapper is the software layer that separates the in-memory objects from the database. Its responsibility is to transfer data between the objects and database and isolate them from each other. If we obtain a Data Mapper, it is not necessary for the in-memory object to know if the database exists or not. The user could directly manipulate the objects via Java command without having knowledge of SQL or database.
Data Transfer Object
Intent Pass data with multiple attributes in one shot from client to server, to avoid multiple calls to remote server. Explanation Real world example We need to fetch information about customers from remote database. Instead of querying the attributes one at a time, we use DTOs to transfer all the relevant attributes in a single shot. In plain words Using DTO relevant information can be fetched with a single backend query.
Dependency Injection
Intent Dependency Injection is a software design pattern in which one or more dependencies (or services) are injected, or passed by reference, into a dependent object (or client) and are made part of the client’s state. The pattern separates the creation of a client’s dependencies from its own behavior, which allows program designs to be loosely coupled and to follow the inversion of control and single responsibility principles. Explanation Real world example
Domain Model
Intent Domain model pattern provides an object-oriented way of dealing with complicated logic. Instead of having one procedure that handles all business logic for a user action there are multiple objects and each of them handles a slice of domain logic that is relevant to it. Explanation Real world example Let’s assume that we need to build an e-commerce web application. While analyzing requirements you will notice that there are few nouns you talk about repeatedly.
Double Checked Locking
Intent Reduce the overhead of acquiring a lock by first testing the locking criterion (the “lock hint”) without actually acquiring the lock. Only if the locking criterion check indicates that locking is required does the actual locking logic proceed. Class diagram Applicability Use the Double Checked Locking pattern when there is a concurrent access in object creation, e.g. singleton, where you want to create single instance of the same class and checking if it’s null or not maybe not be enough when there are two or more threads that checks if instance is null or not.
Double Dispatch
Intent Double Dispatch pattern is a way to create maintainable dynamic behavior based on receiver and parameter types. Class diagram Applicability Use the Double Dispatch pattern when the dynamic behavior is not defined only based on receiving object’s type but also on the receiving method’s parameter type. Real world examples ObjectOutputStream
Event Driven Architecture
Intent Send and notify state changes of your objects to other applications using an Event-driven Architecture. Class diagram Applicability Use an Event-driven architecture when you want to create a loosely coupled system you want to build a more responsive system you want a system that is easier to extend Real world examples Chargify, a billing API, exposes payment activity through various events (https://docs.chargify.com/api-events) Amazon’s AWS Lambda, lets you execute code in response to events such as changes to Amazon S3 buckets, updates to an Amazon DynamoDB table, or custom events generated by your applications or devices.
Event Sourcing
Intent Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data. The store acts as the system of record and can be used to materialize the domain objects. This can simplify tasks in complex domains, by avoiding the need to synchronize the data model and the business domain, while improving performance, scalability, and responsiveness.
Execute Around
Intent Execute Around idiom frees the user from certain actions that should always be executed before and after the business method. A good example of this is resource allocation and deallocation leaving the user to specify only what to do with the resource. Explanation Real-world example A class needs to be provided for writing text strings to files. To make it easy for the user, the service class opens and closes the file automatically.
Also known as Simple Factory Static Factory Method Intent Providing a static method encapsulated in a class called the factory, to hide the implementation logic and make client code focus on usage rather than initializing new objects. Explanation Real-world example Imagine an alchemist who is about to manufacture coins. The alchemist must be able to create both gold and copper coins and switching between them must be possible without modifying the existing source code.