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

Anti anti patterns

Feb 11, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Anti anti patternsNick VanderhovenJeroen Horemans

Page 2: Anti anti patterns

@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

Page 3: Anti anti patterns

@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

Page 4: Anti anti patterns

@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 ...

Page 5: Anti anti patterns

@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

Page 6: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Primitive obsession

The Customer number● Elaborate design

Page 7: Anti anti patterns

@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

Page 8: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Composition over inheritance

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

Hundreds lines of code

Page 9: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Composition over inheritanceAnimal abuser

Just use the “ is a “ rule

Page 10: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Blind faith

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

Page 11: Anti anti patterns

@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;

}

Page 12: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Diaper pattern

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

Page 13: Anti anti patterns

@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;}

Page 14: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Nih (Not Invented Here)

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

Page 15: Anti anti patterns

@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

Page 16: Anti anti patterns

@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();

Page 17: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Base beanThe anarchist

AbstractIntegrationTest

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

Page 18: Anti anti patterns

@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

Page 19: Anti anti patterns

@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

Page 20: Anti anti patterns

@nickvdh @Hypernation#Devoxx #junior2professional

Thank you!Nick VanderhovenJeroen Horemans