55 lines
4.3 KiB
Markdown
55 lines
4.3 KiB
Markdown
# db-subclass-to-dto
|
||
|
||
This is a workspace for creating three exercises.
|
||
|
||
## Explore a repository with LLM diagrams
|
||
|
||
Explore a repository using prompts for a coding agent to create Mermaid and PlantUML diagrams. We're focusing on class diagrams and sequence diagrams to get an idea of what is going on. We use the starting point of the second exercise for this.
|
||
|
||
## Factor out domain objects from ActiveRecord-like structures
|
||
|
||
Factor out domain objects, domain entities, from a structure that is previously subclass-based.
|
||
|
||
Say you use a structure like Active Record or Entity Framework where you have an active record class and your domain class subclasses from the active record class.
|
||
|
||
This super class gives you some easy features like finding an object by attribute. You can quite quickly structure an application while it is also persisted.
|
||
|
||
For instance you can say, "I want to have a customer, I want to have an order. And oh yes, I'm doing this for a webshop." So you have objects, relations, attributes, and you can all easily save them in your database.
|
||
|
||
This is fine when your application is small and you're just starting out. It allows you to very quickly scaffold an application. But it can become painful when your data doesn't have the right shape for it. So performance is slow. At some point as your application grows, you probably want to be more deliberate in how you deal with data.
|
||
|
||
### How do we factor out domain classes?
|
||
|
||
To get away from the inheritance structure with an 'abstract' class tied to the database, we need two or three database-bound concrete classes and some relations.
|
||
|
||
We pre-deliver some classes that we already migrated to the new structure and we demo it. We create a mapping for writing and reading a domain class. And we make sure that running the existing tests against the fake database that we have for the exercise is **really slow.**
|
||
|
||
### Sequence diagrams come in handy
|
||
|
||
The sequence diagrams that we made in the first exercise will come in handy. Because in order to do this, you do start wondering how does this web application find a client? How can we see clients? How can we create an order? And what happens to the flow through the application as we do this?
|
||
|
||
You need to understand the application flow to choose the kind of mapping that you use. Therefore we are going to reuse the analysis we did in the first exercise. Instructions for participants will be pre-structured, so they can focus on doing the exercise instead of devising exacp prompts.
|
||
|
||
## Spike: Static analysis and Extract Method refactoring with Roslyn
|
||
|
||
The third part is a spike in creating an extract method refactoring using Roslyn, the C# static analysis tooling that comes as part of C# more or less.
|
||
|
||
It's an additional NuGet download but it is quite powerful.
|
||
|
||
This is a simple command line app that allows you to specify the name of a file, the starting line and the end line and it will give you an analysis of dependencies inside the method that you need to decide which things could lend itself to extracting to a method, what the parameters could be and what the return value could be.
|
||
|
||
This is work in progress so this is not something to share with participants yet, unless it is in the form of a demo after participants have prompted diagrams.
|
||
|
||
But it is part of a flow where:
|
||
|
||
1. you iterate and you prompt,
|
||
2. create visualisations
|
||
3. extract things into a skill
|
||
4. extract moldable tools to make the skill faster and more reliable
|
||
|
||
Skills and tools together create a flywheel where you can do things that happen again and again more reliably and faster. Speed through quality.
|
||
|
||
## aside on why skills and tools in the line of moldable development
|
||
|
||
You go, ah I often seem to make sequence diagrams. Okay, can we make something deterministic to create these sequence diagrams so it's faster and more reliable? Or in my case I don't like, well I like the extract method stuff in JetBrains IDEs but I need to do some steps before to find the parameters, extract variables, extract the methods with these variables as parameters then inline the variables again and I was wondering if I could do that more smoothly in the flow with a coding agent. That also means that going further I could do things like forbid extracted methods from having Async in all parts, but see if we can extract parts without side effects first.
|