You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
- no more nested if else conditions i.e. less cyclomatic complexity
- code in object oriented way
- compose your code naturally
- highly cohesive code
- loosely coupled code
- build any feature in days
- all concerns are abstracted
- no more hard codings
- no abuse/over-use of throwing exceptions
- proper error handling
- use of builder, template, decorator, compositional, callback patterns
- feed stats for higher level objectives e.g. circuit breaker pattern
How to design ?
- a theoretical design is implemented via code/pseudo logic
- Initial sections talks about various scenarios of using this approach
- later on, one can find the core implementation details
- code/pseudo logic follows Java conventions w.r.t class & namespaces
- extends StorageCheckExecutor
- boolean isActivationWarn = false
- public boolean isActivationWarn()
- public executor onActivationWarn(StorageCheckCallback)
- if isChecksPassed && isActivationWarn then execute the StorageCheckCallback
- return this
StorageCheckExecutor.java (builder pattern)
- entries = Map<ECStorageProperties, String>
- boolean exitChecksOnError = true
- public executor getEntries()
- will return a clone of entries
- public executor withChecks()
- will create a new instance of entries
- will return this
- public executor addEntry()
- will add a new entry to entries & return this
- boolean isChecksError
- will return not issuccess
- boolean isChecksSuccess
- will return true if there are no errors
- boolean isChecksPassed
- will return true if there all checks have passed
- boolean isChecksFailed
- will return true if at least one check has failed
- getCheckErrors
- will return the filtered entries that contain only check errors
- getCheckMessages
- will return the filtered entries that contain only check messages
- getPassedChecks
- will return the filtered entries that contain only the PASSED checks
- getFailedChecks
- will return the filtered entries that contain only the FAILED checks
- continueChecksOnError
- will continue executing check based methods even with previous errors
- exitChecksOnError
- default behavior
- will not execute any check based methods if there were previous errors
- public executor onChecksError(StorageCheckCallback)
- if isError is true then execute the StorageCheckCallback
- return this
- public executor onChecksSuccess(StorageCheckCallback)
- if isSuccess is true then execute the StorageCheckCallback
- return this
- public executor onPassedChecks(StorageCheckCallback)
- if isChecksPassed is true then execute the StorageCheckCallback
- return this
- public executor onFailedChecks(StorageCheckCallback)
- if isChecksFailed is true then execute the StorageCheckCallback
- return this
- public executor isPoolAvailable()
- if exitonerror && iserror then return this
- checkInst = new IsUniqueVolumeCheck()
- checkInst.check(entries)
- return this
- public executor isUniqueVolume()
- if exitonerror && iserror then return this
- checkInst = new IsPoolAvailableCheck()
- checkInst.check(entries)
- return this
ECStorageCheck.java
all classes extending this class should be designed to be truthy checks
in other words all the check classes should set
PASSED for success &
FAILED for error or failure
e.g. have IsUniquePoolCheck than IsDuplicatePoolCheck
e.g. have IsPoolInMaintenance than IsPoolNotInMaintenance
above convention will help in better readability & lead to better maintenance
private static Unsafe getUnsafe()
{
try
{
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
private static final Unsafe unsafe = getUnsafe();
Higher Order Functions
function isPrime(num) {
return num > 2 &&
!Immutable.range(2, num)
.some(function(){
return num % n === 0;
})
}
Range(2, 50).filter(function(n){
return isPrime(n);
}).toList();
- without higher order
ArrayList results = new ArrayList();
for (int i = 1; i < 200; i++) { //stateful variables
boolean isPrimeNumber = true; //more stateful variables
for (int j = 2; j < i; j++) { //even more...
if (i % j == 0) {
isPrimeNumber = false;
break;
}
}
if (isPrimeNumber) {
results.add(i); //what if this was parallel?
}
}
- solving the bigger problems
- old way
var primes = [];
var i = 0;
while(primes.length < 10000) {
if(isPrime(i)) {
primes.push(i);
}
i++;
}
- new way
var primes = Range(1, Number.MAX_VALUE).filter(function(n){
return isPrime(n);
}).take(10000);
Chapter 6
- rule based programming
- alternatively known as condition, action pair programming
- Rules
- Rule Condition Action
- R1 C1 A1
- similar to events based programming
- rule based is 2 step process
- Events
- Event What Happened Handler
- E1 xyz do this
- Implementation
- Tasks
- contain module state
- a set of rules
- a goal
- applyRules()
- Module
- contain one or more tasks
- operates by repeatedly calling applyRules() method
- events may cause a task to fall out of its goal state
while (! goalSatisfied()) {
for (rule : rules) {
if (preconditionSatisfied(rule)) {
execute(rule.action);
}
}
}
- ref - http://blog.acolyer.org/2016/01/19/dcft/
Chapter 7
ref - https://github.com/npryce/make-it-easy
The text was updated successfully, but these errors were encountered:
What will this lead to ?
How to design ?
Chapter 1
Chapter 2
A sample package that depends on DB, AMQP & core
Chapter 3
A sample package that depends on DB, AMQP & core
Chapter 4
A sample core package that has no dependencies on other packages
Chapter 5
The text was updated successfully, but these errors were encountered: