Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface/1 #7

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
953f07f
Add BankAppWithdrawalService
NimeshPiyumantha Mar 14, 2023
9d72fd8
Update main class
NimeshPiyumantha Mar 14, 2023
1458c66
update BankAppWithdrawalService
NimeshPiyumantha Mar 14, 2023
f9d6ea4
update BankAppWithdrawalService
NimeshPiyumantha Mar 14, 2023
1e6a0e3
Update main class
NimeshPiyumantha Mar 14, 2023
eba2b7e
Add Services Pakage
NimeshPiyumantha Mar 14, 2023
33df784
Update main class
NimeshPiyumantha Mar 14, 2023
e5273ba
update BankAppWithdrawalService
NimeshPiyumantha Mar 14, 2023
3041d0e
update BankAppWithdrawalService
NimeshPiyumantha Mar 14, 2023
07931a2
Update main class
NimeshPiyumantha Mar 14, 2023
f1607a2
Update main class
NimeshPiyumantha Mar 14, 2023
0fe40ab
Add Services Pakage
NimeshPiyumantha Mar 14, 2023
7b8e967
update BankAppWithdrawalService
NimeshPiyumantha Mar 14, 2023
8ff8e69
update BankAppWithdrawalService
NimeshPiyumantha Mar 14, 2023
1e15184
Add _02_Liskov-Substitution-Principle
NimeshPiyumantha Mar 14, 2023
afcd157
Update main class
NimeshPiyumantha Mar 14, 2023
dd0c89e
Add _02_Liskov-Substitution-Principle
NimeshPiyumantha Mar 15, 2023
e592a0b
Update class
NimeshPiyumantha Mar 15, 2023
11b1d1e
Update main class
NimeshPiyumantha Mar 15, 2023
0aae2ba
Update Root
NimeshPiyumantha Mar 15, 2023
043bca9
Create License
NimeshPiyumantha Mar 15, 2023
12f8d72
Update Content
NimeshPiyumantha Mar 17, 2023
a56de9a
Update Content
NimeshPiyumantha Mar 17, 2023
1b77744
Update Content
NimeshPiyumantha Mar 17, 2023
c8298b3
Update Content
NimeshPiyumantha Mar 17, 2023
6644da8
Update Content
NimeshPiyumantha Mar 17, 2023
e383128
Update Content
NimeshPiyumantha Mar 21, 2023
53f6a38
Update Content
NimeshPiyumantha Mar 21, 2023
6e583ce
Update Content
NimeshPiyumantha Mar 21, 2023
c9c265d
Update Content
NimeshPiyumantha Mar 21, 2023
692d723
Update Content
NimeshPiyumantha Mar 21, 2023
7312ad0
Update Content
NimeshPiyumantha Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
6 changes: 6 additions & 0 deletions .idea/jpa-buddy.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 65 additions & 27 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions License
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Nimesh_Piyumantha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file modified README.md
Binary file not shown.
58 changes: 58 additions & 0 deletions _01_Open-Close-Principle/src/BankAppWithdrawalService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import service.Account;

/**
* @author : Nimesh Piyumantha
* @since : 0.1.0
**/
public class BankAppWithdrawalService {
/* public void depositToSavingsAccount(double amount){
System.out.println(amount + " Deposited to your Savings Account.!");
}

public void depositToCurrentAccount(double amount){
System.out.println(amount + " Deposited to your Current Account.!");
}

public void withdrawFromSavingsAccount(double amount){
System.out.println(amount + " Withdrawn from your Savings Account.!");
}

public void withdrawFromCurrentAccount(double amount){
System.out.println(amount + " Withdrawn from your Current Account.!");
}

*//* I want to implement another feature for Banking App Withdrawal Service*//*

public void depositToSalarySaverAccount(double amount){
System.out.println(amount + " Deposited to your Salary Server Account.!");
}

public void withdrawFromSalarySaverAccount(double amount){
System.out.println(amount + " Withdrawn from your Salary Server Account.!");
}

*//* So here for adding a new feature I had to modify the class *//*
*//* So, unfortunately we have violated the Open / Close principle *//*
*//* Why.? *//*
*//* In Open/Close principle a class should be closed for modifications but opened for extensions *//*
*//* But here we did modifications rather than doing extensions *//*
*//* S0, we violate the rule */

Account account;

public BankAppWithdrawalService(Account account) {
this.account = account;
}

public void depositToAccount(double amount){
account.deposit(amount);
}
public void withdrawFromAccount(double amount){
account.withdraw(amount);
}

/* Now what..? */
/* Now if there were thousands of account types in the future, no matter */
/* It can be used through the Account Class */
/* Then this class should not be modified (Closed for modifications), but this class is open for extensions */
}
44 changes: 42 additions & 2 deletions _01_Open-Close-Principle/src/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
import service.Account;
import service.types.CurrentAccount;
import service.types.SalarySaverAccount;
import service.types.SavingAccount;

/**
* @author : Nimesh Piyumantha
* @since : 0.1.0
**/
public class Main {
/*SOLID*/
/* O - Open / Close Principle */
/*
*This principle states that the software entities should be open for extensions but close
* for modifications
* */
public static void main(String[] args) {
System.out.println("Hello world!");

/*BankAppWithdrawalService bankAppWithdrawalService = new BankAppWithdrawalService();

bankAppWithdrawalService.depositToCurrentAccount(100000);
bankAppWithdrawalService.withdrawFromCurrentAccount(5000);

bankAppWithdrawalService.depositToSalarySaverAccount(200000);
bankAppWithdrawalService.withdrawFromSalarySaverAccount(100000);*/



/* Let's deposit for Savings Account Bank App Withdrawal Service */
Account savingAccount= new SavingAccount();
BankAppWithdrawalService bankAppWithdrawalService1 = new BankAppWithdrawalService(savingAccount);
bankAppWithdrawalService1.depositToAccount(100000);
bankAppWithdrawalService1.depositToAccount(40000);


Account currentAccount= new CurrentAccount();
BankAppWithdrawalService bankAppWithdrawalService2 = new BankAppWithdrawalService(currentAccount);
bankAppWithdrawalService2.depositToAccount(200000);
bankAppWithdrawalService2.depositToAccount(30000);


Account salaryServer= new SalarySaverAccount();
BankAppWithdrawalService bankAppWithdrawalService3 = new BankAppWithdrawalService(salaryServer);
bankAppWithdrawalService3.depositToAccount(500000);
bankAppWithdrawalService3.depositToAccount(100000);

/* This is what we called as Open / Close Principle */
}
}
}
12 changes: 12 additions & 0 deletions _01_Open-Close-Principle/src/service/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package service;

/**
* @author : Nimesh Piyumantha
* @since : 0.1.0
**/
public abstract class Account {
/* Extract the basic services and place them here */
/* Make it abstract because there is nothing to implement here */
public abstract void deposit(double amount);
public abstract void withdraw(double amount);
}
19 changes: 19 additions & 0 deletions _01_Open-Close-Principle/src/service/types/CurrentAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package service.types;

import service.Account;

/**
* @author : Nimesh Piyumantha
* @since : 0.1.0
**/
public class CurrentAccount extends Account {
@Override
public void deposit(double amount) {
System.out.println(amount + " Deposited to your Current Account.!");
}

@Override
public void withdraw(double amount) {
System.out.println(amount + " Withdrawn from your Current Account.!");
}
}
19 changes: 19 additions & 0 deletions _01_Open-Close-Principle/src/service/types/SalarySaverAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package service.types;

import service.Account;

/**
* @author : Nimesh Piyumantha
* @since : 0.1.0
**/
public class SalarySaverAccount extends Account {
@Override
public void deposit(double amount) {
System.out.println(amount + " Deposited to your Salary Saver Account.!");
}

@Override
public void withdraw(double amount) {
System.out.println(amount + " Withdrawn from Salary Saver Account.!");
}
}
19 changes: 19 additions & 0 deletions _01_Open-Close-Principle/src/service/types/SavingAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package service.types;

import service.Account;

/**
* @author : Nimesh Piyumantha
* @since : 0.1.0
**/
public class SavingAccount extends Account {
@Override
public void deposit(double amount) {
System.out.println(amount + " Deposited to your Savings Account.!");
}

@Override
public void withdraw(double amount) {
System.out.println(amount + " Withdrawn from your Savings Account.!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Loading