Anti anti patterns

20
@nickvdh @Hypernation #Devoxx #junior2professional Anti anti patterns Nick Vanderhoven Jeroen Horemans

Transcript of Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Anti anti patternsNick VanderhovenJeroen Horemans

@nickvdh @Hypernation#Devoxx #junior2professional

Anti anti patterns

Nick : The professional with several successful projectsJeroen : The anti pattern advocate whose project just failed

All code samples are modifications of real code

@nickvdh @Hypernation#Devoxx #junior2professional

Anti anti patterns

Nick : The professional with several successful projectsJeroen : The anti pattern advocate whose project just failed

All code samples are modifications of real code

@nickvdh @Hypernation#Devoxx #junior2professional

Big ball of mud

● To avoid this○ 256 maven modules○ 6 levels of poms○ Every bounded context has

■ An Api■ An enum module■ A build module■ A domain module■ A ...

@nickvdh @Hypernation#Devoxx #junior2professional

Big ball of mudThe spaghetti monster

● Try to keep it simple● Limit your maven structure to the minimum● Add api modules and others when needed

@nickvdh @Hypernation#Devoxx #junior2professional

Primitive obsession

The Customer number● Elaborate design

@nickvdh @Hypernation#Devoxx #junior2professional

Primitive obsessionPrimitive Phobia

● The Customer number○ What did you try to solve?○ Did it have business logic? ○ Was it easy to refactor? ○ Test creation data hell or heaven

@nickvdh @Hypernation#Devoxx #junior2professional

Composition over inheritance

● Composition of the domain model○ Chihuahua encapsulates dog○ Dog encapsulates animal

Hundreds lines of code

@nickvdh @Hypernation#Devoxx #junior2professional

Composition over inheritanceAnimal abuser

Just use the “ is a “ rule

@nickvdh @Hypernation#Devoxx #junior2professional

Blind faith

● We went for 100% test coverage○ Tested every getter, setter, hashcode○ 2 fulltime devs adding all missing tests

@nickvdh @Hypernation#Devoxx #junior2professional

Blind faithThe crazy blind typer

● Even better is to not write the lines yourself○ Testing is important○ Test first is even better○ Don’t overdo it

@Getter@Builder@ToString@EqualsAndHashCode@AllArgsConstructorpublic class Option {

private String label; private Boolean active;

}

@nickvdh @Hypernation#Devoxx #junior2professional

Diaper pattern

● Catched every exception● Wrapped all exceptions● Throw it further up

@nickvdh @Hypernation#Devoxx #junior2professional

Diaper patternDiaper Genie

● Right handling on the right level● Frameworks can help you (spring)● In some cases, just let it go

@Override@SneakyThrowspublic Result <T> find(String id) { List<Account> accounts = repository.find(id); return accounts;}

@nickvdh @Hypernation#Devoxx #junior2professional

Nih (Not Invented Here)

● Never write your own framework!○ We did a lot of copy paste○ Boilerplate FTW ?

@nickvdh @Hypernation#Devoxx #junior2professional

Nih (Not Invented Here)The Boiler Plater

● business value > boilerplate○ A custom annotation is not a crime○ Reflection is not evil, but use it wisely○ Aspects can help you out

@nickvdh @Hypernation#Devoxx #junior2professional

Base bean

No god classes on my watch

public class SomeImportantIntegrationTest{

@Rule public ApplicationLoadingRule applicationRule = new ApplicationLoadingRule (); @Rule public RestServiceStubRule restStubRule = new RestServiceStubRule(); @Rule public DataSourceCreatingRule datasourceRule = new DataSourceCreatingRule(); @Rule public DataPreparationRule cleanRule = new DataPreparationRule(); @Rule public DataCreationRule dataRule = new DataCreationRule(); @Rule public MakeItAllWorkRule workRule = new MakeItAllWorkRule();

@nickvdh @Hypernation#Devoxx #junior2professional

Base beanThe anarchist

AbstractIntegrationTest

@RunWith(SpringRunner.class)public class ImportantIntegrationTest extends AbstractIntegrationTest {

@nickvdh @Hypernation#Devoxx #junior2professional

KISS

● Your code should focus on business value anyway

● Anti patterns are not a silver bullet

● As with normal patterns use it wisely

● Let frameworks help you out

● Refactor at the right time

@nickvdh @Hypernation#Devoxx #junior2professional

KISSThe anti pattern troll

● Your code should focus on business value anyway.

● Anti patterns are not a silver bullet.

● As with normal patterns use it wisely.

● Let frameworks help you out

● Refactor at the right time

@nickvdh @Hypernation#Devoxx #junior2professional

Thank you!Nick VanderhovenJeroen Horemans