Software

MVC Pattern

The pattern is useful when UI is needed.

MVC Diagram.png

The Model contains the underlying data and logic that users want to see and manipulate. A key part of the MVC pattern that the model is self-contained. It has all of the state, methods and other data that it needs to exist on its own. Model focuses solely on managing the information for the system.

The View gives a user a way to see the model or at least parts of it (with buttons, images and other user interface). Responsible only for visual appearance of the system.

The Controller corresponds with control object that receives the events and coordinate actions.

Software

Observer Pattern

Visualization example: let’s say you want to know about the new articles of this blog. You can make software which will check the updates every 1 minute or every 1 hour or even a day. But maybe you need to know immediately, then the observer pattern can help, where the blog will notify you every time a new post is added. You would subscribe to the blog. Every time when new post is published, the blog will notify each subscriber, including you. Hence you don’t need to pull for this information at some interval.

Subject – blog, will keep the list of Observers (subscribers to the blog).

We’ll have a Subject superclass, that defines three methods:

  • Allow a new observer to subscribe.
  • Allow a current observer to unsubscribe.
  • Notify all observers about a new blog post.
Continue reading “Observer Pattern”
Software

Mediator Pattern

Imagine the next situation, you have the smart home where devices communicate to each other and do one or another action dependent on the state of another device.

No Mediator Visualization Diagram.png

The visualization looks complicated and will be even more complicated if needed additional connections between the devices. To simplify the design, must to implement the Mediator pattern, this is how it should looks:

Continue reading “Mediator Pattern”
Software

Command Pattern

The pattern encapsulates the request as an object of its own. Usually, when one object makes a request for a second object to do an action, the first object will call a method of the second object and the second object would complete the task.

Common way:

No Command Pattern Visualization Diagram.png

Visualization of the Command design pattern:

Command Pattern Visualization Diagram.png

In this way, the Sender doesn’t need to know about the receiver and the methods to call.

The Command pattern has another object that invokes the command object to complete whatever task it is supposed to do, called the invoker.

Continue reading “Command Pattern”
Software

Disable bots detection in Sitecore

There are may be needs for you to test some visits in Sitecore to determine each visit precisely but some of them are not handled because Sitecore may think this is not real interactions, especially if make interactions via JMeter, Locust or K6. To disable bots detection you should follow the next steps:

  1. Open the C:\inetpub\wwwroot\<instance name>\App_Config\Sitecore\Marketing.Tracking\Sitecore.Analytics.Tracking.config
  2. Find two settings:
    • Analytics.AutoDetectBots
    • Analytics.Robots.IgnoreRobots

Set the both values of the settings from true to to false.

<!--  ANALYTICS AUTO DETECT BOTS
            Enable auto detection of bots.
            Default: true
-->
<setting name="Analytics.AutoDetectBots" value="false" />

<!--  ANALYTICS ROBOTS IGNORE ROBOTS
            Ignore requests and do not write information to the Analytics database when the visitor 
            classification identifies the visitor as a robot.
            Default: true
-->
<setting name="Analytics.Robots.IgnoreRobots" value="false" />

Now each visits will be considered as a valid visit and each visit will be tracked.

Software

Chain of Responsibility Pattern

A chain of objects that are responsible for handling requests. Its a series of objects that are linked together.

Chain of Responsibility Visualization Diagram.png

When a client object sends a request, the first handler in the chain will try to process it. If a handler can process the request, the request ends at this handler. If a handler cannot deal with the request, the handler will send a request to the next handler nd so on. If any handler can process it, then the request if not satisfied.

Continue reading “Chain of Responsibility Pattern”
Software

Template Method Pattern

This is behavioral design pattern, which means it focus on ways that individual objects collaborate to achieve a common goal.

The Template Method can be helpful if you have 2 classes with similar functionality, which apply generalization principle.

This UML diagram has the essential components: a public template method and abstract methods in the superclass. These abstract methods are implemented in the subclasses. There is also one step common to all: reachDestination. It is private because only the method in the superclass needs to access it.

Template Method Class Diagram.png
Continue reading “Template Method Pattern”
Software

Decorator Pattern

Using the decorator pattern you can build functionality by stacking objects, which allows objects to dynamically add behaviors to others.

The next diagram is helpful to understand the Decorator pattern:

Decorator Aggregation Diagram Visualization.png

This is how aggregation stack looks like. The Object A is a base object because it doesn’t contain another object. It will have its own set of behaviors. Object B aggregates Object A allowing Object B augment the behaviors of Object A. We can continue add objects to stack where Object C aggregates Object B and augment behaviors of Object B. The relation is always 1 to 1 in decorator design pattern in order to build up the stack so that one object is on top of another.

To achieve an overall combination of behavior for the stacked objects, you would call upon the top element which is object C, then C -> B -> A. Object A responds with its behavior, then object B adds its incremental behavior and object C adds its incremented behavior.

Continue reading “Decorator Pattern”
Software

Proxy Pattern

Proxy acts as a simplified or lightweight version of the original object where the proxy object is still able to accomplish the same tasks, but may delegate requests to the original object to achieve them. The proxy object itself can hide sensitive information of the original object when interacting with another objects.

3 main reasons to use proxy design pattern:

  1. To act as a virtual proxy – where the proxy class is used in place of a real subject class that is resource intensive to instantiate (this is commonly used on images and web pages, because a single high definition image can be extremely large).
  2. To act as a protection proxy – in order to control access to the real subject class (role management system).
  3. To act as a remote proxy – where the proxy class is local and the real subject class exists remotely (like a Google documents where web browser has all the objects it needs locally, which also exists on Google servers).
Proxy Class Diagram.png
Continue reading “Proxy Pattern”