/16@yegor256 1
How Anemic Objects

Kill OOP
Yegor Bugayenko
/16@yegor256 2
1. Procedural programming
2. Object thinking (programming)?
3. Practical example
4. What is anemic model?
5. Refactoring
6. Let’s discuss
/16@yegor256 3
1. Code is king (how)
2. Imperative
3. Same as hardware
4. Data is visible
/16@yegor256 4
1. Object is king (what)
2. Declarative
3. Same as real world
4. Data is hidden
/16@yegor256 5
a = 3 + 5;
new Sum(3, 5);
/16@yegor256 6
complexity is growing
because
data has no semantic
/16@yegor256 7
OOP was supposed to
become a solution
/16@yegor256 8
“Objects expose
behavior and data”
— article about

Procedural Programming
/16@yegor256 9
API DB
book1
book2
book1 = API.fetch();
book2.isbn = book1.isbn;
book2.title = book1.isbn;
DB.save(book2);
/16@yegor256 10
class Book {
public String isbn;
public String title;
}
/16@yegor256 11
class Book {
private String isbn;
private String title;
public String getIsbn();
public String getTitle();
public void setIsbn(String);
public void setTitle(String);
}
/16@yegor256 12
1. Data is still visible
2. Still imperative
3. No semantic
/16@yegor256 13
API
DB
new DBBook(new APIBook());
/16@yegor256 14
class APIBook implements Book {
String title() {
// make HTTP request
// parse JSON and
// return title
}
}
/16@yegor256 15
class DBBook implements Book {
private Book book;
String title() {
String title = this.book.title();
// save title to the DB
return title;
}
}
/16@yegor256 16
what do you
think?

How Anemic Objects Kill OOP