19 CEO Dashboard Examples for Business Leaders
Let's rewind to the 1990s. Data used to be stored on servers and CEOs relied on basic tools to make optimal decisions. No dashboards, nothing. When you use Power BI with a solid...
Kapil Panchal - July 21, 2021
Listening is fun too.
Straighten your back and cherish with coffee - PLAY !
In this blog, first, we’ll have some overview about Structural Design Pattern, why we use it, its types and we’ll understand about adapter pattern which is a type of structural design pattern. Let’s try to make things easier to understand with an example.
A Structural design pattern is a type of design pattern which we generally use in the case of large project structures where there are many different types of classes and various objects.
Structural design pattern deals with how different classes work together in a cohesive manner. One class uses properties of difference classes and vice-a- versa by using the OOPs i.e. Object-Oriented Programming Language concepts like inheritance or polymorphism.
It makes it easier for us to understand that what is the relationship of different classes related to one another.
There are 7 types of structural design patterns which are as below.
Now let us focus on the Adapter Pattern.
As from the above description, we had a brief idea about the adapter pattern that it is used when we require to adapt to our client’s requirements.
So we convert one interface into another as the client wanted it to be.
Due to this, the adapter pattern is also known as wrapper pattern because it wraps the structure interface into another which would be easier for the customer to use.
We can reuse our code or other functionality according to requirement.
We can have two different objects interact with each other.
We can have two different objects interact with each other.
Each entity has its own attributes and methods like for credit cards it is bank details and card details. For bank details, attributes are bank name, account holder name, and methods like set bank name, get bank name, set account holder’s name, get account holder’s name, get account number, etc. For Banks, customer methods are to get bank details and get a credit card.
As we can see above in the diagram Bank details will extend bank customers and implement a credit card interface.
The main Interface - So this is the interface that the client will actually use.
The client - The actual request will come from here and interact with the adapter class.
The adapter class - This class is a wrapper class it will implement the interface and modify the specifications according to needs. It will send the required specifications after modification according to the adapter class.
The adapter class - This is the class that will interact with the adapter class to use the functionality from it. It will tell the adapter class what kind of specification is needed.
// Interface Credit Card
public interface CreditCard { public void giveBankDetails(); public String getCreditCard(); }
//Class Bank Details
public class BankDetails { private String bankName; private String accHolderName; private long accNumber; public String getBankName() { return bankName; } public void setBankName(String bankName) { this.bankName = bankName; } public String getAccHolderName() { return accHolderName; } public void setAccHolderName(String accHolderName) { this.accHolderName= accHolderName; } public long getAccNumber() { return accNumber; } public void setAccNumber(long accNumber) { this.accNumber = accNumber; } }
//Class Bank Details
import java.io.BufferedReader; import java.io.InputStreamReader; public class BankCustomer extends BankDetails implements CreditCard { public void giveBankDetails() { Try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println(“Enter the account holder name :"); String customername = br.readLine(); System.out.print("\n"); System.out.print("Enter the account number:"); long accno = Long.parseLong(br.readLine()); System.out.print("\n"); System.out.print("Enter the bank name :"); String bankname = br.readLine(); setAccHolderName(customername); setAccNumber(accno); } catch(Exception e) { e.printStackTrace(); } @Override public String getCreditCard() { long accno=getAccNumber(); String accholdername=getAccHolderName(); String bname=getBankName(); return ("The Account number "+accno+" of "+accholdername+" in "+bname+ " bank is valid and authenticated for issuing the credit card.”); } }
// Main class
Public class AdapterPatternDemo { public static void main(String args[]) { CreditCard targetInterface=new BankCustomer(); targetInterface.giveBankDetails(); System.out.print(targetInterface.getCreditCard()); } }Output
Enter the account holder name: Raj Khurana
Enter the account number: 100401580002
Enter the bank name: State Bank of India
The Account number 100401580002 of Raj Khurana in State Bank of India bank is valid and authenticated for issuing the credit card.
In this blog, we learned various design patterns provided by Java and also in other languages which follow OOPC (Object Oriented Programming Language) concepts. We majorly focused on structural design patterns and in particular the adapter pattern.
Build Your Agile Team
Let's rewind to the 1990s. Data used to be stored on servers and CEOs relied on basic tools to make optimal decisions. No dashboards, nothing. When you use Power BI with a solid...
Imagine walking into a meeting where critical decisions need to be made—fast. You need clear, flexible data that you can analyze on the spot. But what if your insights are locked inside...
Clear insights mean smarter decisions, and this is what data storytelling does. It helps you speak a language that you quickly understand. Like for example, you are a CTO dealing with...