Why you shouldnt use django for that

Post on 21-Feb-2017

293 views 2 download

transcript

Why you shouldn’t useDjango for that

Architecture, the lost

yearsRobert C. Martin

“Web” is not an architecture.

Frameworks are not architecture.

Django is a tool, not architecture.

WAIT!What does this even mean?

Ivan Stepaniuk

@istepaniuk

Application metaphor, the three layers

1 32

1.Interact with the user, both ways

1 32

3. Interact with outside world, other systems

1 32

2. The code that justifies the app existence

1 32

Are these layers equally important?

Do we build them the same way?

Do these change at the same pace?

It is all about CHANGE

OKHow does business logic look like?

PatternsEnterprise Application Architecture

Martin Fowler

Transaction Script

Modeled as procedures

+ Easiest to understand.+ Obvious transaction boundaries. - Difficult to de-duplicate.

Table Module

Modeled as objects and Record Sets

+ No DB vs. OO impedance mismatch.- Model is database-centric. - Objects, but not really OO.

Domain Model

Modeled after the business you work with.

+ Real OOP, with all the OO advantages.- Hardest to comprehend and switch to. - Code overhead for simple logic.

Domain Model

Modeled after the business you work with.

+ Real OOP, with all the OO advantages.- Hardest to comprehend and switch to. - Code overhead for simple logic.

Which pattern should I use?

Which one should we use?

Effo

rt to

enh

ance

Complexity of the business logic

Which one should we use?

Effo

rt to

enh

ance

Complexity of the business logic

7.42

Which pattern does Django follow?

Domain Model Architecture Antipatterns

Anemic Domain Model- Objects have state, but no behavior- The Business is somewhere else

Leads to:- Upside down Transaction Script- God objects

Anemic Domain Model- Objects have state, but no behavior- The Business is somewhere else

Leads to:- Upside down Transaction Script- God objects

Mixins!To inject concerns

Table Driven Domain Model- The data model is the domain model- All objects backed up by a tableLeads to:- High viscosity- Complex, slow, fragile tests- CRUD obsession

Table Driven Domain Model- The data model is the domain model- All objects backed up by a tableLeads to:- High viscosity- Complex, slow, fragile tests- CRUD obsession

CREATEREADUPDATEDELETE

DATABASEDATABASEDATABASEDATABASE

Connected Domain ModelIn a connected system, elements are highly available to each other.Adding the first feature to a connected system is cheap …

… the cost of all those connections is that subsequent featuresare very likely to interact with previous features, driving up the the cost …

In a modular design, connections are deliberately kept to a minimum.The cost of the first feature is likely to be higher …

Features are less likely to interact in a modular system, though,leading to a steady stream of features at relatively constant cost.

- Kent Beck

Connected Domain Model

WAIT!OK, Active Record is bad, but

what about productivity?

Django vs. OOP

Django vs. OOPIs not the debate here

Questions?Or come and ask me later!

Thank you!Oh, and we are hiring!

@istepaniuk