Leave Nothing Exceptional in Exceptions
Course Content
0 / 79 completedThe Reasons to Avoid Enumerations
Alternatives to Enumerations
Converting Enumeration to a Class
The Reasons to Never Stringify Data
Reaping the Benefits of String Encapsulation
Avoiding Primitive Types Altogether
Example - Modeling Money
Persistence - Small-scale CQRS and DDD
Demonstrating Persistence
Summary
Understanding the Role of Null
Why Compilers Still Rely on Null
Using Callback on Optional Content
Overloading Existing APIs to Never Return Null
Returning an Optional Object
Implementing Custom Option Type
Consuming the Option
Persistence - Creating Complex Domain Objects
Summary
Course Overview
What’s Wrong with Status Codes
Understanding Effects of Throwing Exceptions
What Exceptions Are Not Meant to Do
Leave Nothing Exceptional in Exceptions
Returning a Polymorphic Type Instead of an Excep
Separating Positive and Negative Return Values
Inventing the Either Type
Consuming the Either Type
Summary
The First Law of Defensive Programming
Version Check
What Follows in This Course
Traditional Defensive Techniques
Defensive Design - An Experiment
Called Method Cannot Defend
Defining Function Domains
Summary
Creating Objects
Creating Consistent Objects
Pros and Cons of Multiple Constructors
Understanding Limitations of the Constructor
Promoting Constructor into Builder
Variations in the Builder Implementation
Summary
Reaping the Benefits of Constructor Validation
Defending in Property Setters
Understanding Distinct Kinds of Properties
Defending in Complex Mutations
Function Domains Revisited
When Constructor Depends on Multiple Objects
Creating Objects in Small Steps
Persistence and Parameterized Constructors
Summary
Introducing Guard Clauses
Guarding Against Null Only
Dont Guard Business Rules
Removing Guards Through Design
Turning Domain Rules into Rule Objects
Turning Rule Objects into Active Elements
Completing the Students Filter
Persistence - Querying View Models
Summary
Encapsulating State
Keeping Related Data Together
Turning Chained Ifs into the Chain of Rules
Making Friends with Regular Expressions
Replacing Branching with Regular Expressions
Moving Expressions out to Configuration
Persistence - Creating and Updating Domain Objects
Summary
Reconsidering Immutable Objects
Turning Classes Immutable
Avoiding Aliasing Bugs Altogether
The Downside of Immutability
Constrained Mutability with Set-once Properties
Consuming Semi-mutable Objects
Using Historical Model
Implementing Simple Historical Model
Summary