Этот проект я использую для разных экспериментов. Надеюсь, не запутаетесь :-)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. refactor the code so it's at the same level of abstraction (SLAP). | |
0. | |
Range range = new Range(8000, 8005); | |
var port = Port.freeWithin(range); | |
1. | |
int from = 8000; | |
int to = 9000; |
- README.md: no information on how to run and test the app.
- README.md: no information on minimum runtime requirements (Java 11+).
- Unused code:
getSurname()
,getLoans()
,setLoans(...)
etc. Best practice: never write/generate code "just in case". - Packaging: according to Common Closure Principle, classes that change together must be packaged together. So, instead of putting closely related classes in different packages (
exceptions
,models
,enums
,repositories
,requests
,services
), put them together or split by domain (lending
,client
). More info here. - API: the API tries to be, but is not RESTful. E.g. plurals should be used:
/loans
,/loans/{clientUUID}
- Architecture: domain model leaks to the API. Instead, we should decouple the domain model from our API/screens, because they change for different reasons. In practice, our APIs should always return DTOs, not entities.
- Excepti
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.homework.services; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
import com.fasterxml.jackson.databind.DeserializationFeature; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.homework.exceptions.CountryResolverException; | |
import com.homework.models.Country; | |
import com.homework.repositories.CountryRepo; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.beans.factory.annotation.Configurable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. refactor the code so it's at the same level of abstraction (SLAP). | |
int from = 8000; | |
int to = 9000; | |
IntStream | |
.rangeClosed(from, to) | |
.mapToObj(Port::new) | |
.filter(throwingPredicate(Port::isFree)) // sneakily throws the original exception (faux-pas) | |
.filter(wrap().predicate(Port::isFree)) // wraps unchecked exception (noexceptions) | |
.findFirst(); |
- Exercises and possible solutions
- Slides
- Homework
- Demo project – this one has some interesting code examples
- How to transform data and avoid nesting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. refactor the code so it's at the same level of abstraction (SLAP). | |
int from = 8000; | |
int to = 9000; | |
int availablePort = IntStream | |
.rangeClosed(from, to) | |
map(Port::new) | |
.filter(Port::isAvailable) | |
.findFirst(); | |
class Port { |
- Exercises and possible solutions
- Solution to Exercise #20 (transforming data w/o nesting)
- Slides
- Homework
- Demo project – this one has some interesting code examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Fix bad naming. | |
class ShoppingCart { | |
UUID id(); | |
boolean isEligibleForFreeShipping(); | |
remove(OrderItem item); | |
add(OrderItem item); | |
Collection<OrderItem> items(); | |
} | |
Good morning, team!
Below I'll share some "the missing parts".
- The idea of "Behind every request, there is an unsatisfied need" comes from the Nonviolent Communication book by Marshall Rosenberg. It's the best communication book ever written and it has helped me understand people better, and build the family I always dreamed of.
- Other 5 forces of influence are: