Skip to content

Instantly share code, notes, and snippets.

@stolarczykt
stolarczykt / PolishTaxPolicy.java
Last active Jan 27, 2020
Functional cohesion example
View PolishTaxPolicy.java
public class PolishTaxPolicy implements TaxPolicy {
public Money calculateTax(Money amount) {
//method body
return tax;
}
}
@stolarczykt
stolarczykt / DocsRepository.java
Created Jan 27, 2020
Communicational cohesion example
View DocsRepository.java
public class DocsRepository {
public Doc findById(DocId id) {
//method's body
return doc;
}
public Doc save(Doc document) {
//method's body
return doc;
@stolarczykt
stolarczykt / DocsInitializer.java
Created Jan 27, 2020
Temporal cohesion example
View DocsInitializer.java
public class DocsInitializer {
public void createBaseDirectoryStructure() {
//creating required directory structure
}
public void cacheDefaults() {
//caching required defaults
}
@stolarczykt
stolarczykt / MathUtils.java
Created Jan 27, 2020
Logical cohesion example
View MathUtils.java
public class MathUtils {
public static double sin(double a) {
//method's body
return sin;
}
public static double cos(double a) {
//method's body
return sin;
View CoincidentalCohesion.java
public class CoincidentalCohesion {
public void log(Exception e) {
//method body
}
public void sendMessage(Recepient recepient) {
//method body
}
@stolarczykt
stolarczykt / StampAndDataCoupling.java
Created Jan 25, 2020
Examples of stamp and data coupling
View StampAndDataCoupling.java
//Stamp coupling
public EmployeeAddress findAddressFor(EmployeeData employeeData) {
EmployeeAddress address = repository
.findByEmployeeId(employeeData.getId())
//method body
return address;
}
//Data coupling
@stolarczykt
stolarczykt / ControlCoupling.java
Created Jan 25, 2020
Example of control coupling
View ControlCoupling.java
public void save(boolean validationRequired) {
if (validationRequired) {
validate();
store();
} else {
store();
}
}
@stolarczykt
stolarczykt / ContentCoupling.java
Created Jan 25, 2020
Content coupling example
View ContentCoupling.java
Class<?> clazz = Image.class;
Object imageInstance = clazz.newInstance();
Field descriptionField = imageInstance
.getClass().getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField
.set(imageInstance, "Pen Pineapple Apple Pen");