SlideShare a Scribd company logo
INTRODUCTION TO CLASS AND APPLICATION
DESIGN
PATRICK KOSTJENS
Java Beginners Meetup, May 2017
1
ABOUT ME
PATRICK KOSTJENS
So ware developer
2
INTRODUCTION
3
WHY DO WE CARE?
Easier to understand
Maintainability
Team projects
Reuseability
Long term productivity
Reduce errors
4
HOW TO MAKE SURE?
Ask others
Easy to write unit tests?
Look at it later (a week, a month)
5
CLASS DESIGN
6
NAMING MATTERS
public int[] run(int[] x) {
int y;
for (int i = 1; i < x.length; i++) {
for (int j = i; j > 0; j--) {
if (x[j] < x[j - 1]) {
y = x[j];
x[j] = x[j - 1];
x[j - 1] = y;
}
}
}
return x;
}
public int[] doInsertionSort(int[] input) {
int temp;
for (int i = 1; i < input.length; i++) {
for (int j = i; j > 0; j--) {
if (input[j] < input[j - 1]) {
temp = input[j];
input[j] = input[j - 1];
input[j - 1] = temp;
}
}
}
return input;
}
7 . 2
KEEP THINGS SMALL
Small methods
Small classes
Small packages
No deep nesting
Limited number of parameters
No duplication
Use local context as much as possible
Use common sense
Small slides
The magic number 7
8
COMPOSITION
Object composition is a way to combine simple objects
or data types into more complex ones.
- Michelle Yaiser
A vehicle has an engine
9 . 2
ENCAPSULATION
A mechanism to hide implementation details so that only the necessary
information is exposed.
Bad
public class Employee {
public BigDecimal salary = new BigDecimal(50000.00);
}
10 . 2
Good
public class Employee {
private BigDecimal salary = new BigDecimal(50000.00);
public BigDecimal getSalary() {
return salary;
}
public void setSalary(BigDecimal salary) {
this.salary = salary;[
}
}
10 . 3
INHERITANCE
Inheritance means a class is based on another class.
public class Animal {
// Animal implementation
}
public class Dog extends Animal {
// Specific Dog functionality
}
public class Cat extends Animal {
// Specific Cat functionality
}
11 . 2
INTERFACES
A set of methods that can be implemented by one or more classes.
public interface Displayable {
void display();
}
public class Paper implements Displayable {
public void display() {
// Implementation to display using Paper
}
}
public class Monitor implements Displayable {
public void display() {
// Implementation to display using Monitor
}
}
12 . 2
DESIGN PATTERNS AND PRINCIPLES
13
DESIGN PATTERNS
Higher level of abstraction
Prevent duplication
Help encapsulation
Help keep things small
There are many, we'll discuss a few
14
Single responsibility principle
Open/closed principle
Liskov subsitution principle
Interface segregation principle
Dependency inversion principle
SOLID
15
BUILDER PATTERN
Helps with immutability
Reduces parameters
Hides implementation well
Hard to read/use
public class BankAccount {
private final String accountNumber;
private final String name;
private BigDecimal balance;
private final List<Transaction> transactions;
private final DateTime creationDate;
private final List<Contractant> contractants;
public BankAccount(String accountNumber, String name, BigDecimal balance, List<Transaction
DateTime creationDate, List<Contractant> contractants) {
this.accountNumber = accountNumber;
this.name = name;
this.balance = balance;
this.transactions = transactions;
this.creationDate = creationDate;
this.contractants = contractants;
}
// Getters
}
new BankAccount("NL12BANK345667", "TestAccount", new BigDecimal(100), transactions, new DateTi
16 . 2
Improved version
public class BankAccount {
private final String accountNumber;
private final String name;
private BigDecimal balance;
private final List<Transaction> transactions;
private final DateTime creationDate;
private final List<Contractant> contractants;
private BankAccount(String accountNumber, String name, BigDecimal balance, List<Transactio
DateTime creationDate, List<Contractant> contractants) {
this.accountNumber = accountNumber;
this.name = name;
this.balance = balance;
this.transactions = transactions;
this.creationDate = creationDate;
this.contractants = contractants;
}
public static class Builder {
private String accountNumber;
private String name;
private BigDecimal balance;
private List<Transaction> transactions;
private DateTime creationDate;
Usage
Longer, but easier to read
new BankAccount.Builder()
.withAccountNumber("NL12BANK345667")
.withName("TestAccount")
.withBalance(new BigDecimal(100))
.withContractants(contractants)
.withCreationDate(new DateTime(1980, 1, 1))
.withTransactions(transactions)
.createBankAccount();
16 . 4
SINGLETON PATTERN
Use the singleton pattern when you want only one instance of a class in the
entire system.
public final class Singleton {
private static final Singleton INSTANCE = new Singleton();
private Singleton() {}
public static Singleton getInstance() {
return INSTANCE;
}
}
17 . 2
MVC PATTERN
18
EXERCISE
19
EXERCISE
Take one of your projects and try to check and improve on the things we
discussed.
Try to discuss your solutions and improvements with each other.
20
BOOKS
And many others
Code Complete, Steve McConnel
The Pragmatic Programmer, Andrew Hunt, David
Thomas
Clean Code, Robert C. Martin
Agile So ware Development, Robert C. Martin
21
FINAL REMARKS
Carefully pick names
Don't add unnecessary complexity
No single right or wrong way
Practice
22

More Related Content

PPTX
Design Patterns: Back to Basics
PDF
React in 45 Minutes (Jfokus)
PPTX
Dev Cast Dependency Injection
PDF
Design patterns for fun and profit
PDF
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
PPTX
classes & objects in cpp overview
PDF
JavaProgrammingManual
PDF
C# Starter L06-Delegates, Event Handling and Extension Methods
Design Patterns: Back to Basics
React in 45 Minutes (Jfokus)
Dev Cast Dependency Injection
Design patterns for fun and profit
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
classes & objects in cpp overview
JavaProgrammingManual
C# Starter L06-Delegates, Event Handling and Extension Methods

What's hot (16)

PDF
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...
PPTX
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
PPT
Parceable serializable
PDF
Knot.x: when Vert.x and RxJava meet
PPT
04 Data Access
PDF
Nikita Galkin "Looking for the right tech stack for GraphQL application"
 
PDF
A coding fool design patterns
DOCX
Bt0082, visual basic
PPTX
Dependency Injection for Android
PPTX
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
DOC
Ip project
PPS
Singleton
PPT
Singleton
PDF
Java program-to-add-two-matrices
PPTX
Ip project visual mobile
PDF
ButterKnife
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet W...
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
Parceable serializable
Knot.x: when Vert.x and RxJava meet
04 Data Access
Nikita Galkin "Looking for the right tech stack for GraphQL application"
 
A coding fool design patterns
Bt0082, visual basic
Dependency Injection for Android
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Ip project
Singleton
Singleton
Java program-to-add-two-matrices
Ip project visual mobile
ButterKnife
Ad

Similar to Java beginners meetup: Introduction to class and application design (20)

PPTX
Design patterns(red)
PDF
Design Patterns - GOF
PDF
Java performance
PPTX
Core java oop
PDF
Design Patterns
PDF
JAVA-PPT'S.pdf
PPT
P Training Presentation
PPTX
JAVA-PPT'S-complete-chrome.pptx
PPTX
JAVA-PPT'S.pptx
PDF
The maze of Design Patterns & SOLID Principles
PDF
Boost Your Development With Proper API Design
PPT
Design_Patterns_Dr.CM.ppt
PDF
Design patterns in Java - Monitis 2017
PPTX
OOPs in Java
PPT
10-design-patterns1.ppt.software engineering
PPTX
Design pattern
PDF
Key points of good software programming
PPSX
Oop features java presentationshow
PPT
Design poo my_jug_en_ppt
PPTX
Effective java
Design patterns(red)
Design Patterns - GOF
Java performance
Core java oop
Design Patterns
JAVA-PPT'S.pdf
P Training Presentation
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S.pptx
The maze of Design Patterns & SOLID Principles
Boost Your Development With Proper API Design
Design_Patterns_Dr.CM.ppt
Design patterns in Java - Monitis 2017
OOPs in Java
10-design-patterns1.ppt.software engineering
Design pattern
Key points of good software programming
Oop features java presentationshow
Design poo my_jug_en_ppt
Effective java
Ad

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Digital Strategies for Manufacturing Companies
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
ai tools demonstartion for schools and inter college
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Introduction to Artificial Intelligence
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
System and Network Administration Chapter 2
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
AI in Product Development-omnex systems
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Adobe Illustrator 28.6 Crack My Vision of Vector Design
2025 Textile ERP Trends: SAP, Odoo & Oracle
Digital Strategies for Manufacturing Companies
PTS Company Brochure 2025 (1).pdf.......
ai tools demonstartion for schools and inter college
Odoo POS Development Services by CandidRoot Solutions
Which alternative to Crystal Reports is best for small or large businesses.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Introduction to Artificial Intelligence
Operating system designcfffgfgggggggvggggggggg
How to Choose the Right IT Partner for Your Business in Malaysia
How to Migrate SBCGlobal Email to Yahoo Easily
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
System and Network Administration Chapter 2
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Reimagine Home Health with the Power of Agentic AI​
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
AI in Product Development-omnex systems
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

Java beginners meetup: Introduction to class and application design

  • 1. INTRODUCTION TO CLASS AND APPLICATION DESIGN PATRICK KOSTJENS Java Beginners Meetup, May 2017 1
  • 2. ABOUT ME PATRICK KOSTJENS So ware developer 2
  • 4. WHY DO WE CARE? Easier to understand Maintainability Team projects Reuseability Long term productivity Reduce errors 4
  • 5. HOW TO MAKE SURE? Ask others Easy to write unit tests? Look at it later (a week, a month) 5
  • 7. NAMING MATTERS public int[] run(int[] x) { int y; for (int i = 1; i < x.length; i++) { for (int j = i; j > 0; j--) { if (x[j] < x[j - 1]) { y = x[j]; x[j] = x[j - 1]; x[j - 1] = y; } } } return x; }
  • 8. public int[] doInsertionSort(int[] input) { int temp; for (int i = 1; i < input.length; i++) { for (int j = i; j > 0; j--) { if (input[j] < input[j - 1]) { temp = input[j]; input[j] = input[j - 1]; input[j - 1] = temp; } } } return input; } 7 . 2
  • 9. KEEP THINGS SMALL Small methods Small classes Small packages No deep nesting Limited number of parameters No duplication Use local context as much as possible Use common sense Small slides The magic number 7 8
  • 10. COMPOSITION Object composition is a way to combine simple objects or data types into more complex ones. - Michelle Yaiser
  • 11. A vehicle has an engine 9 . 2
  • 12. ENCAPSULATION A mechanism to hide implementation details so that only the necessary information is exposed.
  • 13. Bad public class Employee { public BigDecimal salary = new BigDecimal(50000.00); } 10 . 2
  • 14. Good public class Employee { private BigDecimal salary = new BigDecimal(50000.00); public BigDecimal getSalary() { return salary; } public void setSalary(BigDecimal salary) { this.salary = salary;[ } } 10 . 3
  • 15. INHERITANCE Inheritance means a class is based on another class.
  • 16. public class Animal { // Animal implementation } public class Dog extends Animal { // Specific Dog functionality } public class Cat extends Animal { // Specific Cat functionality } 11 . 2
  • 17. INTERFACES A set of methods that can be implemented by one or more classes.
  • 18. public interface Displayable { void display(); } public class Paper implements Displayable { public void display() { // Implementation to display using Paper } } public class Monitor implements Displayable { public void display() { // Implementation to display using Monitor } } 12 . 2
  • 19. DESIGN PATTERNS AND PRINCIPLES 13
  • 20. DESIGN PATTERNS Higher level of abstraction Prevent duplication Help encapsulation Help keep things small There are many, we'll discuss a few 14
  • 21. Single responsibility principle Open/closed principle Liskov subsitution principle Interface segregation principle Dependency inversion principle SOLID 15
  • 22. BUILDER PATTERN Helps with immutability Reduces parameters Hides implementation well
  • 23. Hard to read/use public class BankAccount { private final String accountNumber; private final String name; private BigDecimal balance; private final List<Transaction> transactions; private final DateTime creationDate; private final List<Contractant> contractants; public BankAccount(String accountNumber, String name, BigDecimal balance, List<Transaction DateTime creationDate, List<Contractant> contractants) { this.accountNumber = accountNumber; this.name = name; this.balance = balance; this.transactions = transactions; this.creationDate = creationDate; this.contractants = contractants; } // Getters } new BankAccount("NL12BANK345667", "TestAccount", new BigDecimal(100), transactions, new DateTi 16 . 2
  • 24. Improved version public class BankAccount { private final String accountNumber; private final String name; private BigDecimal balance; private final List<Transaction> transactions; private final DateTime creationDate; private final List<Contractant> contractants; private BankAccount(String accountNumber, String name, BigDecimal balance, List<Transactio DateTime creationDate, List<Contractant> contractants) { this.accountNumber = accountNumber; this.name = name; this.balance = balance; this.transactions = transactions; this.creationDate = creationDate; this.contractants = contractants; } public static class Builder { private String accountNumber; private String name; private BigDecimal balance; private List<Transaction> transactions; private DateTime creationDate;
  • 25. Usage Longer, but easier to read new BankAccount.Builder() .withAccountNumber("NL12BANK345667") .withName("TestAccount") .withBalance(new BigDecimal(100)) .withContractants(contractants) .withCreationDate(new DateTime(1980, 1, 1)) .withTransactions(transactions) .createBankAccount(); 16 . 4
  • 26. SINGLETON PATTERN Use the singleton pattern when you want only one instance of a class in the entire system.
  • 27. public final class Singleton { private static final Singleton INSTANCE = new Singleton(); private Singleton() {} public static Singleton getInstance() { return INSTANCE; } } 17 . 2
  • 30. EXERCISE Take one of your projects and try to check and improve on the things we discussed. Try to discuss your solutions and improvements with each other. 20
  • 31. BOOKS And many others Code Complete, Steve McConnel The Pragmatic Programmer, Andrew Hunt, David Thomas Clean Code, Robert C. Martin Agile So ware Development, Robert C. Martin 21
  • 32. FINAL REMARKS Carefully pick names Don't add unnecessary complexity No single right or wrong way Practice 22