PV168
Rendering & Filtering
Back to Seminar Tasks 2 & 3
- Relatively straightforward
- Copy & Paste worked well
- Still there were some challenges - where?
Back to Seminar Task 4
- Completely different story
- Many of you struggled significantly
- Why was that?
- Copy & Paste still necessary
- Are the abstractions friendly?
- You may have reached your Java limits
So why do we need the Renderer concept?
- Isn’t
Object.toString()
enough?
- Its audience are developers (logs, debugging, …)
- NEVER expose
toString()
products to end users!
- Different components may require different format
- And customer-facing strings may be localized
AbstractRenderer
benefits
- Shields you from ugly Swing API
ListCellRenderer<T>
TableCellRenderer
- Brings type safety on top of old API
- Feel free to reuse
AbstractRenderer
in your projects
- As well as other abstractions you find useful
Filtering in Swing
RowSorter
abstraction API too wide
- Both sorting and filtering
RowFilter
still too vague
EntityMatcher
adapts it from rows to entities
Additional complexity
- Heterogeneous data in filters
- Distinct objects (enums or entities)
- Groups (all distinct objects or their subsets)
- Leading to abstraction
Either<L, R>
- Functional API
- Lambdas & Streams
Optional
Recommended reading
Effective Java (Third Edition)
Joshua Bloch
Addison-Wesley Professional, 2017
https://www.amazon.com/dp/0134685997
Effective Java
- Book not only about Java
- Almost half of the book is about OOP in general
- Present since 2001 (the first edition)
- With code examples specifically in Java
- Items are heavily cross-referenced
- Start reading anywhere you like
Josh Bloch (the author)
- Java architect between 1996 and 2004
- Designed a lot of cool stuff for Java
- The Java Collections Framework (Java 1.2)
- Assertions, amendments to
Throwable
(Java 1.4)
- Generics, Annotations and
Enum
(Java 1.5)
- try-with-resources and
AutoCloseable
(Java 1.7)
Structure of the book
- Chapter 2 (Items 1—9)
- Creating and Destroying Objects (mostly) generic
- Chapter 3 (Items 10—14)
- Methods Common to All Objects Java-specific
- Chapter 4 (Items 15—25)
- Classes and Interfaces (mostly) generic
- Chapter 5 (Items 26—33)
Structure of the book (continued)
- Chapter 6 (Items 34—41)
- Enums and Annotations Java-specific
- Chapter 7 (Items 42—48)
- Lambdas and Streams Java-specific
- Chapter 8 (Items 49—56)
- Chapter 9 (Items 57—68)
- General Programming generic
Structure of the book (continued)
- Chapter 10 (Items 69—77)
- Exceptions (mostly) generic
- Chapter 11 (Items 78—84)
- Concurrency (mostly) generic
- Chapter 12 (Items 85—90)
- Serialization Java-specific
Literature section at PV168 pages
- Code Smells
- Refactoring
- Effective Java
- Design Patterns