Top Banner
Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys)
40

Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Jun 24, 2020

Download

Documents

dariahiddleston
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: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Java Package by Feature

Java Day 2014, Athens Greece

Kostis Kapelonis (Trasys)

Page 2: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

02/05/2014 2

An imaginary story

…for a supermarket

Page 3: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

I want to buy some toothpaste

02/05/2014 3

Page 4: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Supermarket is organized by color (!!!)

02/05/2014 4

Page 5: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

I would have to ask

-Where do I find

toothpaste?

-“It depends on the

colour”

02/05/2014 5

Page 6: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

I would have to ask

-Why by colour?

-Because it is very

easy for us to load

the shelves

02/05/2014 6

Page 7: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

WTF?

02/05/2014 7

Page 8: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

I would then go to a “normal” supermarket

…where products are grouped by usage

02/05/2014 8

Page 9: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

The context

02/05/2014 9

Java Enterprise Applications

Page 10: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Java Enterprise applications

02/05/2014 10

• Big codebase (200k+ LOC)

• No developer knows all parts

• Original authors are not in the team

• In development for 2+ years

• In production for 3+ years

Page 11: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Think the future today

Numbers vary from 60% to 80%

02/05/2014 11

Page 12: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

This talk is about

Organization of Java

packages by feature.

02/05/2014 12

…and not by layer

Page 13: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Package by layer

02/05/2014 13

• Package according to

business purpose

• All relevant classes

inside.

Page 14: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Agenda – (the maintenance nightmare)

1. Clients always request features (not layers)

2. Encapsulation (follow the OOP paradigm)

3. Enforcing a sound software architecture

4. Plugin system (lego development)

5. Project code should grow horizontally (feature

scope)

02/05/2014 14

Page 15: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part I - Clients think in features

02/05/2014 15

“There is a bug in the

billing application”

Page 16: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Clients think in features

02/05/2014 16

“This report has errors”

Page 17: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Clients think in features

02/05/2014 17

“The budget screen is

missing a button”

Page 18: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Clients think in features

02/05/2014 18

“When I save a

document I get an error”

Page 19: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Clients think in features (never in layers)

02/05/2014 19

“I think we should use

AOP in our persistence

layer” Not!

Page 20: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

A real story

…with a software company this time

02/05/2014 20

Page 21: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

A real story

Enthusiastic software developer

Goes to a new company!

Assigned to a project

Gets his first issue to work on!

“The profits report has a math

error”

02/05/2014 21

Page 22: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Is this easy?

02/05/2014 22

• Nothing makes

any sense

• Don’t know where

to start looking

• Usually you need

to ask around

Page 23: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

A better alternative

02/05/2014 23

• Instant detection of

affected code

• Changes contained in

that package

• No need to look at the

rest of the code

• Isolate junior developers

Page 24: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part II - Encapsulation

02/05/2014 24

OOP in the package level

Page 25: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part II - Encapsulation

02/05/2014 25

• All classes are public !

• Everything can be

accessed by everything

else

Page 26: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part II - Encapsulation

02/05/2014 26

• DAO is package private

• Bean could be package

private as well

• Only Service is public

Page 27: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part III – Good architecture

02/05/2014 27

Enforce a valid system design

Page 28: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part III – Good architecture

02/05/2014 28

A good design

Page 29: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part III – Good architecture

Package by layer can

easily lead to …

02/05/2014 29

Page 30: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part III – Good architecture

02/05/2014 30

A bad design!

Page 31: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part IV- Plugin structure

The Holy Grail of Enterprise applications

02/05/2014 31

Page 32: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part IV- Plugin structure

Packages are self-contained!

They can be added in other

projects

They can be removed

They can be converted to

jars/wars/ears/OSGI etc.

02/05/2014 32

Page 33: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part V- Project size

02/05/2014 33

Page 34: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Part V- Project size

02/05/2014 34

Assume you have two enterprise projects

The second could be just a newer version

First project is 100.000 lines of code

Second project is 1.000.000 lines of code

How do they look in Eclipse?

Page 35: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Package by Layer

02/05/2014 35

Project 1 Project 2

Page 36: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Package by Layer – A big project

02/05/2014 36

• Thousands of “actions”,

DAOs

• Usually alphabetically sorted

• Very hard to work with

• Cause for code duplication

Page 37: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Package by feature

02/05/2014 37

Project 1 Project 2

Page 38: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Closing remarks

Next time you add a new class to a

package named:

controllers

dialogs

actions

DAO

02/05/2014 38

Think Again!

Page 39: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Closing remarks

There is also a hybrid

approach. First level is by

feature and second layer

is by layer

Also avoid package by

pattern (shown on

picture)

02/05/2014 39

Page 40: Java Package by Feature › webfolder › s › delivery_production › ... · Java Package by Feature Java Day 2014, Athens Greece Kostis Kapelonis (Trasys) 02/05/2014 2 An imaginary

Discussion

02/05/2014 40