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

Oracle Advanced SQL Clauses

Group By

group by attr1, attr2

group by ROLLUP(attr1, attr2)

group by CUBE(attr1, attr2)

Rank, Dense_RANK, ROW_number:

RANK() OVER (ORDER BY PRICE) as "PR",
ROW_NUMBER() OVER (ORDER BY PRICE) as "PR"
DENSE_RANK() OVER (ORDER BY C DESC NULLS LAST) as "R"
DENSE_RANK() OVER (PARTITION by C ORDER BY P) as "PR"
RANK() OVER (ORDER BY P) as "PR"
avg(C) OVER() AS "AC"
MIN(Y) KEEP (DENSE_RANK FIRST ORDER BY Y) as "FirstItem"
MIN(Y) KEEP (DENSE_RANK LAST ORDER BY Y) as "LASTItem"

Hierarchical Query:

START WITH employee_id = 102
CONNECT BY FOLLOWING m_id = e_id;

Keep First or Last Row

KEEP (DENSE_RANK FIRST ORDER BY …)
KEEP (DENSE_RANK LAST ORDER BY …)

PARTITION BY on RANK/Dense_Rank

RANK()
RANK() OVER
RANK() OVER PARTITION BY
DENSE RANK() OVER
DENSE RANK() OVER PARTITION BY
PARTITION BY …. ORDER BY
ROW_NUMBER() OVER (ORDER By …)
ROWS BETWEEN Unbounded Preceding and CURRENT ROW
RANGE BETWEEN INTERVAL 5 DAY PRECEDING AND INTERVAL ‘5’ DAY Following
ROWS BETWENN 1 PRECEDING and 1 FOLLOWING
DENSE RANK() OVER (PARTITION BY …..)
DENSE RANK() OVER (PARTITION BY …..ORDER BY …)

Oracle Advanced SQL Clauses

Group By