Proxy Pattern

Proxy Pattern:

“Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.

A credit card is a proxy for a bank account, which is a proxy for a bundle of cash. Both implement the same interface: they can be used for making a payment. A consumer feels great because there’s no need to carry loads of cash around. A shop owner is also happy since the income from a transaction gets added electronically to the shop’s bank account without the risk of losing the deposit or getting robbed on the way to the bank.

Click on the images to see them clearly.

In the above UML class diagram, the Proxy class implements the Subject interface so that it can act as substitute for Subject objects. It maintains a reference (realSubject) to the substituted object (RealSubject) so that it can forward requests to it (realSubject.operation()).

UML Class Diagram

https://refactoring.guru/design-patterns/proxy

https://en.wikipedia.org/wiki/Proxy_pattern

Java: Facade Design Pattern

Façade Pattern

“Facade is a structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes.”

“When you call a shop to place a phone order, an operator is your facade to all services and departments of the shop. The operator provides you with a simple voice interface to the ordering system, payment gateways, and various delivery services.”

For a clear view, click on the images (images are from Wikipedia)

Ref: https://refactoring.guru/design-patterns/facade

https://en.wikipedia.org/wiki/Facade_pattern

Java : Decorator Design pattern

Decorator Design pattern:

Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.

Example:

Assume: A notifier class/object can send only email messages. But the application at a later time may want to use text/SMS, FB, or similar messages. With decorator pattern: decorate the Notifier class with other behaviours such as send SMS, send fb message, send twitter message (i.e. may create additional classes/objects (create link to original notifier class with interfaces/inheritance and aggregations/compositions) ). Then the client can use the original notifier class/object but dynamically point to the other classes/objects and use the corresponding sendMessage() method/behaviour for SMS, Text, FB, Twitter or similar messaging/notification.

Note: Inheritance/subclasses can be a choice but they have limitations. Aggregations/Compositions/interfaces will be used for the purpose of Decorator pattern.

Note: “When does a simple wrapper become the real decorator? As I mentioned, the wrapper implements the same interface as the wrapped object. That’s why from the client’s perspective these objects are identical.

Ref: https://refactoring.guru/design-patterns/decorator

https://en.wikipedia.org/wiki/Decorator_pattern

Java Structural Design Patterns

Adapter Design Patterns

Ref: A good read: https://refactoring.guru/design-patterns/adapter

Ref: Wikipedia

Ref: https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-aggregation-vs-composition/

MicroK8s Commands in Ubuntu

MicroK8s Commands in Ubuntu
(- – use double hyphen)

Install
sudo snap install microk8s – -classic
sudo snap install microk8s – -classic – -channel=1.25/stable

Allow Through: Firwall
sudo ufw allow in on cni0 && sudo ufw allow out on cni0
sudo ufw default allow routed

Enable Add Ons
microk8s enable dns
microk8s enable dashboard
microk8s enable storage

You can disable when you need
microk8s disable dns
microk8s disable dashboard
microk8s disable storage

Kubernetes Dashboard
microk8s kubectl get all – -all-namespaces

Retrieve Token
token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
microk8s kubectl -n kube-system describe secret $token

Host your service in Kubernetes
microk8s kubectl create deployment microbot – -image=dontrebootme/microbot:v1
microk8s kubectl scale deployment microbot – -replicas=2

Create service
microk8s kubectl expose deployment microbot – -type=NodePort – -port=80 – -name=microbot-service

Check cluster after a few minutes
microk8s kubectl get all – -all-namespaces

Misc Commands
microk8s status
microk8s enable
microk8s disable
microk8s kubectl
microk8s config
microk8s istioctl
microk8s inspect
microk8s reset
microk8s stop
microk8s start

Ref: https://ubuntu.com/tutorials/install-a-local-kubernetes-with-microk8s#1-overview

Misc. Kubectl/MicroK8s Commands and Output

Application Deployment

Sample MySQL Configurations (application.properties)

Docker File

Java (basic) Interview Questions and Answers

https://youtu.be/IuDpZCRPx-g