Simple Simple Pure Pure Java Java Anton Keks Anton Keks - - PowerPoint PPT Presentation

simple simple pure pure java java
SMART_READER_LITE
LIVE PREVIEW

Simple Simple Pure Pure Java Java Anton Keks Anton Keks - - PowerPoint PPT Presentation

Simple Simple Pure Pure Java Java Anton Keks Anton Keks anton@codeborne.com anton@codeborne.com The Enterprise... The Enterprise... Enterprise Architecture 20 years ago a new field was born, addressing System complexity = more and more


slide-1
SLIDE 1

Simple Simple Pure Pure Java Java

Anton Keks Anton Keks

anton@codeborne.com anton@codeborne.com

slide-2
SLIDE 2

The Enterprise... The Enterprise...

slide-3
SLIDE 3

Enterprise Architecture

20 years ago a new field was born, addressing

System complexity = more and more money for building IT systems Poor business alignment = more difficult to keep those increasingly expensive systems aligned with business need

A problem of more cost, less value Today: even more cost, even less value

slide-4
SLIDE 4

Complexity Complexity

slide-5
SLIDE 5

☠ ☠BOO! BOO!

slide-6
SLIDE 6

Your average Java (web) app Your average Java (web) app

  • Framework(s)
  • Model
  • Portal?
  • Services!
  • Remote services, SOA, EJB
  • JNDI
  • Stubs, generated code
  • How many layers?
slide-7
SLIDE 7

... ...

  • Patterns!
  • Factory, Singleton, Facade
  • Enterprise patterns!
  • DTO, DAO, etc
  • Getters/setters

(what's the deal - generate 'em)

  • JPA, JAXB
  • JMS!
slide-8
SLIDE 8

Bad words Bad words

It's always nice to see guys like SessionServiceContextManager

Layer Tier Bus Context Manager Locator Assembler Bean Broker Facade Transfer Object DAO …

  • r AbstractStrategyFactoryProxyFacadeBuilder
slide-9
SLIDE 9

EAR, WAR, WAR, WAR EAR, WAR, WAR, WAR Configuration, descriptors! Configuration, descriptors! JNDI! JNDI! ESB? ;-) ESB? ;-)

Must be a wizard to make it all run! Must be a wizard to make it all run! Improves job security index :-) Improves job security index :-)

slide-10
SLIDE 10

For a small thing we create For a small thing we create

  • ManagedBean
  • MegaServiceWrapper
  • CoreServiceLocal, Stub (JNDI lookup?)
  • CoreService (&& CoreServiceImpl)
  • AggregatedService
  • ConcreteService
  • ConcreteDAO
  • JPAAdapter
  • ...
slide-11
SLIDE 11

The result? The result?

  • It kills productivity
  • Thousands lines of code, very few

functionality

  • Well hidden ”business logic”
  • N minute deploy time (+ N minutes app

server startup)

  • Oops, sometimes redeploy doesn't work,

need to restart

  • Slow UI responsivness

slide-12
SLIDE 12

What to do? What to do?

  • Concentrate on domain terminology
  • This was the intention of OOP
  • Avoid overly defensive code
  • You are not writing a framework!
  • Fellow developers are friends
  • Follow Clean Code by Robert C. Martin
slide-13
SLIDE 13

Java platform and language Java platform and language

  • Java (EE) is a victim of JCP
  • Many unreal/unusable JSRs
  • Stick to proven open-source stuff
  • Less standards – the better
  • Java language is ok
  • The biggest miss are closures
  • DSLs are possible: Mockito, LambdaJ
  • Don't bloat (generate) your code
slide-14
SLIDE 14

Code style Code style

  • Is your code style limiting readability?
  • Avoid too many line breaks and braces
  • Emphasize what is important

public int size() { if (root == null) { return 0; } else { return root.numSiblings(); } } public int size() { if (root == null) return 0; return root.numSiblings(); } public int size() { return root != null ? root.numSiblings() : 0; }

slide-15
SLIDE 15

Code style Code style

  • Avoid over-indenation (or code ladder)

public void startCharging() { if (customer.hasFunds()) { if (!station.isCharging()) { if (!station.currentlyBooked()) { reallyStartCharging(); return; } } } throw new UnableToStartException(); } public void startCharging() { if (!customer.hasFunds()) throw new UnableToSta if (station.isCharging()) throw new UnableToSta if (station.currentlyBooked()) throw new Unable reallyStartCharging(); }

slide-16
SLIDE 16

Code style Code style

  • Prefer shorter code (use static imports)

import static java.util.Arrays.*; import static java.util.Collections.*; ... return unmodifiableList(asList(1, 2, 3)) List<Integer> list = Arrays.asList(1, 2, 3)); list = Collections.unmodifieableList(list); return list;

Looks a bit like functional programming, isn't it?

slide-17
SLIDE 17

Code style Code style

  • Prefer good naming to comments
  • Avoid getters/setters, equals, hashCode,

toString unless necessary

  • Break free from 'conventions'
  • Work towards a DSL

when(session.currentUser()).thenReturn(fakeUser); assertThat(person.age, is(25)); sort(people, on(Person.class).getAge());

slide-18
SLIDE 18

Proper Java app Proper Java app

  • Jetty Launcher (esp in development)
  • Know the APIs well: servlets, filters, etc
  • Avoid vendor-specific stuff
  • Keep environment-specific configuration

in version control

  • Dependency Injection
  • Avoid scattering cross-cutting concerns
  • DB migrations (w/ liquibase/dbdeploy)
  • Start thin and simple, prefer higher SNR

SNR

slide-19
SLIDE 19

Web UI Web UI

  • Your framework tells you don't need to

know JavaScript? (GWT, JSF, etc)

  • B.S.!
  • Keep it under control: learn basics of

JQuery instead

  • Knockout.js, Backbone.js can help
  • You are not limited with Java syntax on

the client side :-)

slide-20
SLIDE 20

Worth reminding... Worth reminding...

  • Don't Repeat Yourself
  • Keep It Simple Stupid
  • You Ain't Gonna Need It
  • Test Driven Development
slide-21
SLIDE 21

Let's continue on Let's continue on github: github:

github.com/angryziber/simple-java github.com/angryziber/simple-java

job@codeborne.com job@codeborne.com

(or just google: ”gotocon simple java”) (or just google: ”gotocon simple java”)