You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: saga/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,10 @@ Wikipedia says
31
31
32
32
> Long-running transactions (also known as the saga interaction pattern) are computer database transactions that avoid locks on non-local resources, use compensation to handle failures, potentially aggregate smaller ACID transactions (also referred to as atomic transactions), and typically use a coordinator to complete or abort the transaction. In contrast to rollback in ACID transactions, compensation restores the original state, or an equivalent, and is business-specific. For example, the compensating action for making a hotel reservation is canceling that reservation.
33
33
34
+
Flowchart
35
+
36
+

37
+
34
38
## Programmatic Example of Saga Pattern in Java
35
39
36
40
The Saga design pattern is a sequence of local transactions where each transaction updates data within a single service. It's particularly useful in a microservices architecture where each service has its own database. The Saga pattern ensures data consistency and fault tolerance across services. Here are the key components of the Saga pattern:
## Programmatic Example of Separated Interface Pattern in Java
35
39
36
40
The Java Separated Interface design pattern is a crucial software architecture strategy that promotes separating the interface definition from its implementation, crucial for enhancing system flexibility and scalability. This allows the client to be completely unaware of the implementation, promoting loose coupling and enhancing flexibility.
Copy file name to clipboardExpand all lines: serialized-entity/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,10 @@ Wikipedia says
32
32
33
33
> In computing, serialization is the process of translating a data structure or object state into a format that can be stored (e.g. files in secondary storage devices, data buffers in primary storage devices) or transmitted (e.g. data streams over computer networks) and reconstructed later (possibly in a different computer environment). When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of references, this process is not straightforward. Serialization of objects does not include any of their associated methods with which they were previously linked.
## Programmatic Example of Serialized Entity Pattern in Java
36
40
37
41
The Serialized Entity design pattern is a way to easily persist Java objects to the database. It uses the `Serializable` interface and the DAO (Data Access Object) pattern. The pattern first uses `Serializable` to convert a Java object into a set of bytes, then it uses the DAO pattern to store this set of bytes as a BLOB (Binary Large OBject) in the database.
Copy file name to clipboardExpand all lines: serialized-lob/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,10 @@ In plain words
30
30
31
31
> The Serialized LOB design pattern manages the storage of large objects, such as files or multimedia, by serializing and storing them directly within a database.
## Programmatic Example of Serialized LOB Pattern in Java
34
38
35
39
The Serialized Large Object (LOB) design pattern is a way to handle large objects in a database. It involves serializing an object graph into a single large object (a BLOB or CLOB, for Binary Large Object or Character Large Object, respectively) and storing it in the database. When the object graph needs to be retrieved, it is read from the database and deserialized back into the original object graph.
Copy file name to clipboardExpand all lines: servant/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,10 @@ Wikipedia says
34
34
35
35
> In software engineering, the servant pattern defines an object used to offer some functionality to a group of classes without defining that functionality in each of them. A Servant is a class whose instance (or even just class) provides methods that take care of a desired service, while objects for which (or with whom) the servant does something, are taken as parameters.
## Programmatic Example of Servant Pattern in Java
38
42
39
43
The Servant design pattern is a behavioral design pattern that defines a class that provides some sort of service to a group of classes. This pattern is particularly useful when these classes lack some common functionality that can't be added to the superclass. The Servant class brings this common functionality to a group of classes.
Copy file name to clipboardExpand all lines: server-session/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,10 @@ Wikipedia says
34
34
35
35
> A session token is a unique identifier that is generated and sent from a server to a client to identify the current interaction session. The client usually stores and sends the token as an HTTP cookie and/or sends it as a parameter in GET or POST queries. The reason to use session tokens is that the client only has to handle the identifier—all session data is stored on the server (usually in a database, to which the client does not have direct access) linked to that identifier.
## Programmatic Example of Server Session Pattern in Java
38
42
39
43
The Server Session design pattern is a behavioral design pattern that assigns the responsibility of storing session data on the server side. This pattern is particularly useful in the context of stateless protocols like HTTP where all requests are isolated events independent of previous requests.
## Programmatic Example of Service Layer Pattern in Java
45
44
46
45
Our Java implementation uses the Service Layer pattern to streamline interactions between data access objects (DAOs) and the business logic, ensuring a clean separation of concerns.
@@ -358,10 +357,6 @@ INFO [2024-05-27 09:16:40,681] com.iluwatar.servicelayer.app.App: Find wizards
358
357
INFO [2024-05-27 09:16:40,683] com.iluwatar.servicelayer.app.App: Aderlard Boud has 'Fireball'
359
358
```
360
359
361
-
## Detailed Explanation of Service Layer Pattern with Real-World Examples
Copy file name to clipboardExpand all lines: service-locator/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,10 @@ Wikipedia says
33
33
34
34
> The service locator pattern is a design pattern used in software development to encapsulate the processes involved in obtaining a service with a strong abstraction layer. This pattern uses a central registry known as the "service locator", which on request returns the information necessary to perform a certain task. Proponents of the pattern say the approach simplifies component-based applications where all dependencies are cleanly listed at the beginning of the whole application design, consequently making traditional dependency injection a more complex way of connecting objects. Critics of the pattern argue that it is an antipattern which obscures dependencies and makes software harder to test.
## Programmatic Example of Service Locator Pattern in Java
37
41
38
42
The Service Locator design pattern is used to abstract the processes involved in obtaining a service. It uses a central registry, the "service locator", which returns the necessary information to perform a task upon request. This Java design pattern is particularly useful in enterprise Java applications where services need centralized management.
Copy file name to clipboardExpand all lines: service-to-worker/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,10 @@ In plain words
26
26
27
27
> Separates the processing logic from the view in web applications to improve maintainability and scalability.
28
28
29
+
Sequence diagram
30
+
31
+

32
+
29
33
## Programmatic Example of Service to Worker Pattern in Java
30
34
31
35
The Service to Worker design pattern separates the processing logic from the view in web applications to improve maintainability and scalability. It combines the Dispatcher View and Service Locator patterns to facilitate the separation of processing, control flow, and view management in web applications.
## Programmatic Example of Session Facade Pattern in Java
38
42
39
43
The Session Facade design pattern is a structural design pattern that provides a simplified interface to a set of complex subsystems, reducing the complexity for the client. This pattern is particularly useful in situations where the client needs to interact with multiple services or systems but doesn’t need to know the internal workings of each service.
Copy file name to clipboardExpand all lines: sharding/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,10 @@ Wikipedia says
35
35
>
36
36
> There are numerous advantages to the horizontal partitioning approach. Since the tables are divided and distributed into multiple servers, the total number of rows in each table in each database is reduced. This reduces index size, which generally improves search performance. A database shard can be placed on separate hardware, and multiple shards can be placed on multiple machines. This enables a distribution of the database over a large number of machines, greatly improving performance. In addition, if the database shard is based on some real-world segmentation of the data (e.g., European customers v. American customers) then it may be possible to infer the appropriate shard membership easily and automatically, and query only the relevant shard.
## Programmatic Example of Sharding Pattern in Java
39
43
40
44
Sharding is a type of database partitioning that separates very large databases into smaller, faster, more easily managed parts called data shards. The word shard means a small part of a whole. In software architecture, it refers to a horizontal partition in a database or search engine. Each individual partition is referred to as a shard or database shard.
Copy file name to clipboardExpand all lines: single-table-inheritance/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,10 @@ Wikipedia says
36
36
37
37
> Single table inheritance is a way to emulate object-oriented inheritance in a relational database. When mapping from a database table to an object in an object-oriented language, a field in the database identifies what class in the hierarchy the object belongs to. All fields of all the classes are stored in the same table, hence the name "Single Table Inheritance".
## Programmatic Example of Single Table Inheritance Pattern in Java
40
44
41
45
Single Table Inheritance is a design pattern that maps an inheritance hierarchy of classes to a single database table. Each row in the table represents an instance of a class in the hierarchy. A special discriminator column is used to identify the class to which each row belongs.
Copy file name to clipboardExpand all lines: singleton/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,10 @@ Wikipedia says
33
33
34
34
> In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system.
Copy file name to clipboardExpand all lines: spatial-partition/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,10 @@ Wikipedia says
39
39
>
40
40
> For example, in ray tracing, space partitioning helps quickly determine the objects a ray might intersect by narrowing down the search space, leading to faster rendering times. Similarly, in game development, Quadtrees can efficiently manage 2D game environments by segmenting the space into smaller regions, facilitating quicker collision detection and rendering.
## Programmatic Example of Spatial Partition Pattern in Java
43
47
44
48
The Spatial Partition design pattern in Java is a strategic approach for handling multiple objects in expansive game worlds or detailed simulation environments, boosting query efficiency and operational speed. It allows us to efficiently manage these objects and perform operations like collision detection or range queries. The pattern works by dividing the space into smaller, manageable regions, and each object is associated with the region it belongs to. This way, we can limit our operations to a specific region, instead of checking every object against every other object.
Copy file name to clipboardExpand all lines: special-case/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,10 @@ In [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR) Ma
37
37
38
38
> If you’ll pardon the unresistable pun, I see [Null Object](https://java-design-patterns.com/patterns/null-object/) as special case of Special Case.
39
39
40
+
Sequnce diagram
41
+
42
+

43
+
40
44
## Programmatic Example of Special Case Pattern in Java
41
45
42
46
The Special Case Pattern is a software design pattern that is used to handle a specific, often uncommon, case separately from the general case in the code. This pattern is useful when a class has behavior that requires conditional logic based on its state. Instead of cluttering the class with conditional logic, we can encapsulate the special behavior in a subclass.
Copy file name to clipboardExpand all lines: specification/README.md
+4
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,10 @@ Wikipedia says
37
37
38
38
> In computer programming, the specification pattern is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using boolean logic.
## Programmatic Example of Specification Pattern in Java
41
45
42
46
Let's consider a creature pool example. We have a collection of creatures with specific properties. These properties might belong to a predefined, limited set (represented by enums like `Size`, `Movement`, and `Color`) or they might be continuous values (e.g., the mass of a `Creature`). In cases with continuous values, it's better to use a "parameterized specification," where the property value is provided as an argument when the `Creature` is instantiated, allowing for greater flexibility. Additionally, predefined and/or parameterized properties can be combined using boolean logic, offering almost limitless selection possibilities (this is known as a "composite specification," explained further below). The advantages and disadvantages of each approach are detailed in the table at the end of this document.
0 commit comments