Check out a free preview of the full Enterprise Architecture Patterns course

The "Object Modeling Solution" Lesson is part of the full, Enterprise Architecture Patterns course featured in this preview video. Here's what you'd learn in this lesson:

Lukas live codes the solution to the Object Modeling exercise.

Preview
Close

Transcript from the "Object Modeling Solution" Lesson

[00:00:00]
>> We're doing a project with an interface working creating an array of them. And more importantly is we're defining ProjectState in the initialState. So, let us be about this. Typically what I will do when I'm approaching this. For real, is that I start with the interface. So if I'm building a project from scratch.

[00:00:27]
The first thing I do is I'll just scratch out all the interfaces that I can think of for this particular project. So in this case, interface project I am going to extend base entity. And this is why we kind of do this. Let me expand this out a bit.

[00:00:50]
And we're going to fly through this so title, string, description string I'm going to add something in here just for fun. This might not have even been in the solution. Let me check real quick. I don't think it is but I feel like it should have been. Good this completed that's what I was going to do.

[00:01:18]
So I guess my past self realized that hey projects you should be able to describe if they are done or not. So here we have title description and completed. Now, before we go further, just stop mentally in your mind and think of what format form of look like if you're working with this.

[00:01:40]
So, Title, input field, description, maybe a text area like if you wanted to allow, your more chatty co workers. Or clients or customers to really describe this project. And then, completed because it's Boolean. What is that typically going to be? Well, Checkbox typically it's either on or it's off.

[00:02:05]
So with that said, we are going to create two projects, super project and this is gonna have an id one. Title, super project description is going to be this is awesome and completed. Is going to be false. Because we love working on it so much, we just don't want it to end.

[00:02:43]
Now. We'll call this one hell project. I think everybody here probably just immediately thought of a project, they just like, transposed on top of this. I said hell project. They're like, I know one of those. And so in their mind they've mentally filled that in I'm seeing some heads going on the chat.

[00:03:03]
So clearly I'm not the only one who has been on that kind of project. We'll call this help project on Earth. I'm imagining my mom's going to just pop out here at any point be like don't talk like that. Just make it stop. Completed. I'm just gonna lie and tell myself that it is.

[00:03:33]
Alright. So this is just me speaking from my heart to the hearts of all the developers around the world. And we're gonna go projects. So this is an array of projects, And we're just going to add in super Project, And help Project. So far, so good. Now let's take this and flip it just a little bit and turn it into future state.

[00:04:08]
So, what I will do here and for the sake of kind of grouping this all together. I'm kind of keeping the project stuff together and the client stuff together, but. General, what I will do is kind of group my interfaces together, so interface. We'll call this project's state.

[00:04:34]
And. This is going to have projects and the reason why this is not extending base entity is. Because this is actually representing a composition of entities that live like in the database. So this is actually a composed Essentially data structure that we are, we're basically defining here, a project is an array of projects.

[00:05:02]
And Current project is project. All right? And then from here Const newproject. Null, title, description, and completed is false. Okay. Then what we'll do is let's create an instance of our initial state. So const initial projects state is project state. And this is going to have projects so we're able to use that.

[00:06:01]
And then current project is going to be is it new project there we go. All right. We just dump the cell and see if this word. Alright, as expected, and so now, we have kind of from the backside, worked into defining or composite compositing objects. In a way that we can define future step.

[00:06:38]
And then let me just show you something interesting since we're here. And I was not planning on doing this, but what we could do is Do AppState and We could do something like this interface. AppState equals clients State Which is clients, state and projects, state. And so now I can define.

[00:07:35]
My AppState, like this. ClientState is initialClientState, projectsState is initialProjectstate. And so notice what we're doing now is we're just taking objects. And we're just putting them together in a way, where you can now define we take objects. We put them into collections. And we put them into state objects.

[00:08:20]
We put those or feature state objects, we put those together. And now we have application state. And so we're just building on these little bitty ideas. Until they start to look like something.
>> It's wonderful. This really helps me understand how the NgRx works.
>> NgRx, we're not talking about NgRx.

[00:08:42]
>> Inducer [LAUGH]
>> Aah, you spoil the surprise [LAUGH]. So The comment was that this is really helpful. It is helping illuminate how NGRS works well. My response was NGRS who's talking about NGRS or Redux, but those who are a student Like this is where we're going with this is that we are moving into building something that exists to provide proper state management.

[00:09:25]
But we're doing it in a way that is accessible to. A five year old or ten year old like we're doing this piece by piece by piece. I saw an eyebrow raised like a five year old Well, I don't know.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now