< Return to Video

Robert C. Martin - Clean Architecture and Design

  • 0:00 - 4:44
    (The talk starts at 4:45)
  • 4:46 - 4:50
    Alright you all hear me okay?
  • 4:51 - 4:56
    Way in the back up there you hear me alright? Well it's OK, good good good
  • 4:56 - 5:01
    Um what is an electron?
  • 5:04 - 5:08
    So part of atom, everybody knows that, I think
  • 5:08 - 5:18
    It's um.. (Screams from other room) yeah I think so, . I think that's royal ???
  • 5:20 - 5:22
    Electron is part of atom
  • 5:23 - 5:32
    It's carries a unit of electronic charge, negative charge, as oppose to a proton which carries a positive charge
  • 5:32 - 5:42
    It apparently has mass, though not very much, thousands of electron or something like that. Very very small amount of mass
  • 5:43 - 5:55
    And we think of it as a particle, although that's misleading. The electron actually behaves much more like a wave than like a particle
  • 5:55 - 5:59
    Why do we think of it as particle?
  • 5:59 - 6:09
    And the reason we do that is that when an electron interacts it interacts at a location like a particle would
  • 6:09 - 6:16
    But when electron is moving through the space it does not moves the way a particle would
  • 6:16 - 6:21
    It moves as a wave and the wave has no location
  • 6:21 - 6:27
    You look at an ocean wave, and ocean wave can be huge
  • 6:27 - 6:34
    It has no distinct location it has a well defined energy but no distinct location
  • 6:34 - 6:36
    This is how an electron moves
  • 6:36 - 6:42
    Electrons obey a principle and it's a mistruster principle
  • 6:42 - 6:46
    It's called the poly exclusion principle
  • 6:46 - 6:53
    Two electrons bound into the same system will not be in the same state
  • 6:53 - 6:57
    For whatever reason they cannot be in the same state
  • 6:57 - 7:01
    so if there are two electrons in an atom
  • 7:01 - 7:04
    those two electrons must be different somehow
  • 7:04 - 7:08
    Now they might different in the direction of their spin
  • 7:08 - 7:11
    An electron can spin to the left or spin to the right
  • 7:11 - 7:18
    Two electrons that have exactly same energy could fit together spinning one left and one right
  • 7:18 - 7:21
    There's no way to get a third one in there
  • 7:21 - 7:28
    So the next electron must have higher energy and then you can have two more
  • 7:28 - 7:31
    One spinning left one spinning right
  • 7:31 - 7:35
    But if you wanted to add another that would have to be something different about them
  • 7:35 - 7:38
    And you could arrange them differently in space
  • 7:38 - 7:49
    So you could have one group of two this way and another group of two this way and another group of two this way and one group of two in a sphere and that adds up the eight by the way.
  • 7:50 - 7:58
    Most of our atoms that we know of have this need to have 8 electrons in their shells
  • 7:58 - 8:08
    The reason for that is just this nice little geometry. the sphere and then three rows and each one of those can contain two
  • 8:08 - 8:13
    Have you ever thought about water?
  • 8:13 - 8:17
    I got some here. Fascinating substance
  • 8:17 - 8:20
    What's it made of?
  • 8:20 - 8:25
    Two hydrogen atoms one oxygen atom that's what makes a water molecule
  • 8:25 - 8:28
    And what's it shaped like?
  • 8:28 - 8:33
    Mickey mouse! yes, there is big oxygen in the middle and two little hydrogens forming the ears
  • 8:33 - 8:42
    The angle there is the result of (??) the shell arrangement.
  • 8:42 - 8:47
    What makes the hydrogen and oxygen stick together?
  • 8:47 - 8:51
    Think of two atoms, two atoms covered by electrons, two electrons are parallel each other
  • 8:51 - 8:56
    What would make two hydrogens and an oxygen stick together?
  • 8:56 - 9:03
    And it turns out that if you take these two hydrogens and big oxygen you lay them next to each other
  • 9:03 - 9:12
    And you think of the electrons as waves, not particles, then where those waves like to be?
  • 9:12 - 9:20
    And those waves would like to be mostly between protons. Protons in hydrogen atom and protons in oxygen atom
  • 9:20 - 9:25
    So they will congregate those electron waves will congregate more
  • 9:25 - 9:31
    Between two atoms, between three atoms actually, then everywhere else
  • 9:31 - 9:35
    They still go everywhere else that just that more likely to be between them
  • 9:35 - 9:48
    That means there's little extra negative charge between the atoms and that little extra negative charge to tracks the protons and that's covalent bonds
  • 9:48 - 9:54
    Now if you take this Mickey mouse atom and you divide it in half
  • 9:54 - 9:58
    You find there's more negative charge above the one and below the one
  • 9:58 - 10:02
    Cause all that negative charge likes to sit there between the two hydrogen atoms and oxygen atoms
  • 10:02 - 10:08
    So there's more negative charge on one side than the other which means that water molecule is a dipole
  • 10:08 - 10:11
    It is negative one side and positive on the other
  • 10:11 - 10:13
    This is why water is wet.
  • 10:13 - 10:20
    Water sticks to your hand because all the water molecules rotate to stick to the electrically charged surface of your skin
  • 10:20 - 10:23
    Even though it is not very electrically charged
  • 10:23 - 10:34
    This is why water makes it good solvent because the little water molecules would rotate to attract to the parts of the other molecule that they want want to stick to
  • 10:34 - 10:37
    This is why water makes it a good cleanser
  • 10:37 - 10:43
    And this is why water will do one of the most wonderful things you can do with water. Who's done this experiment?
  • 10:43 - 10:52
    You get a water faucet. You turn it on just so you get a really thin stream of water. Not very fast, just tiny stream of water
  • 10:52 - 11:02
    And then you get a balloon and you rub the balloon on your head. And then you hold the balloon close to that stream of water and watch the water bend towards the balloon
  • 11:02 - 11:06
    As all the water molecules turn around get it tracked the electric charge
  • 11:06 - 11:10
    Of course that's not what we supposed to be talking about
  • 11:11 - 11:20
    The name of the talk I'm about to give you is called "Architecture the lost years". It a talk I've been doing for several years.
  • 11:20 - 11:28
    It's about the next step after clean code after clean design.
  • 11:29 - 11:34
    This is about clean system structure
  • 11:34 - 11:38
    And it begins with that
  • 11:38 - 11:47
    This is a directory structure of an application I wrote close to ten years ago now
  • 11:47 - 11:53
    I was studying Rails. Anybody here Ruby programmer, Ruby on Rails programmer?
  • 11:53 - 11:57
    We got a guy over there, waving his hand around. OK.
  • 11:57 - 12:04
    I was learning Rails at that time. And I wrote this application
  • 12:04 - 12:10
    And it was I followed the book. You get the books out. You follow the book
  • 12:10 - 12:14
    Follow all the recommendations of the book and that's what I wound up with
  • 12:14 - 12:20
    And I was happy with that. I put the application away and I didn't look at it again for very long time.
  • 12:20 - 12:27
    Then about three years ago. My son, at my request, wrote an application.
  • 12:27 - 12:32
    And I looked it in and I saw that.
  • 12:32 - 12:36
    Same directory structure.
  • 12:36 - 12:41
    These are two completely different applications. It had nothing to do with each other.
  • 12:41 - 12:45
    But they had same directory structure. And I looked at it and I thought.
  • 12:45 - 12:53
    Wait why did these two applications have the same high level structure?
  • 12:53 - 12:57
    They are two completely different applications.
  • 12:57 - 13:03
    And it occured to me that they had same directory structure because they were both Rails applications.
  • 13:03 - 13:09
    And I asked my self, okay but why is that important?
  • 13:09 - 13:21
    Why is Rails or any framework so important that it would dominate the high level directory structure of an application?
  • 13:21 - 13:25
    And the reason I asset question of myself was because of this.
  • 13:26 - 13:34
    The web is a delivery mechanism. The web is an I/O channel.
  • 13:34 - 13:38
    The web is not architecturally significant.
  • 13:38 - 13:42
    We think of ourselves as writing web applications.
  • 13:42 - 13:45
    We are not writing web applications.
  • 13:45 - 13:52
    We are writing applications that happened to deliver their content over the I/O channel known as the web.
  • 13:52 - 13:58
    And why should that I/O channel dominate us?
  • 14:00 - 14:07
    Does anybody remember when the web became important? 1980? 1990?
  • 14:07 - 14:14
    Anybody remember what a change that was? How radically different everything was?
  • 14:14 - 14:20
    Except that it wasn't. Because we weren't really doing anything new?
  • 14:20 - 14:27
    We were just gathering input from an input source. Processing it and spitting it out to an output source.
  • 14:27 - 14:28
    That's all the web is.
  • 14:28 - 14:31
    Why would web dominate so much?
  • 14:31 - 14:39
    So I started to thinking about architecture. And I started to looking at blue prints.
  • 14:41 - 14:50
    There's blueprint. and if you didn't have the word library staring at you. it wouldn't take you long to figure out that it was a library.
  • 14:50 - 14:52
    Because it's obviously a library.
  • 14:52 - 14:56
    You got a bunch of book shelves in there. You got a bunch of reading tables.
  • 14:56 - 15:06
    There's little computers sitting on tables. There's an area upfront where you have the desk you can borrow or return books
  • 15:06 - 15:11
    It wouldn't take you long to look at that and think "Um.. that must be something like a library."
  • 15:11 - 15:16
    Or here's another one. That's a church. It's obviously a church.
  • 15:16 - 15:21
    Oh, you might mistake it for a theater. Theater and church do have certain synergy to them.
  • 15:21 - 15:30
    But no this is definitely a church. The puse(??), the altar, the classrooms on the outside, the greeting area around the front
  • 15:30 - 15:32
    This is clearly a church.
  • 15:32 - 15:42
    The architecture of this buildings is not telling you how they built. The architecture of this buildings is telling you what they are for.
  • 15:42 - 15:49
    Their intent. Architecture is about intent.
  • 15:49 - 15:56
    And the high level structures of those Rails apps were not communicating intent to me.
  • 15:56 - 16:03
    They were telling me that they were Rails apps. Something wrong with that.
  • 16:03 - 16:06
    And then it occurred to me.
  • 16:06 - 16:15
    This is known problem? It's a solved problem. It was recognized and solved by Iva Jacobson in 1992 when he wrote this book.
  • 16:15 - 16:21
    Who got this book? Anybody read this one? I got a guy here, anybody else?
  • 16:21 - 16:23
    Object-Oriented Software Engineering, if you have. Wonderful Book.
  • 16:24 - 16:30
    It's 1992 little bit old, but it doesn't matter. The principles inside still perfectly good.
  • 16:30 - 16:37
    Notice the subtitle, the subtitle says "A usecase driven approach"
  • 16:37 - 16:45
    Who remembers usecases? Uh.. See? It was very popular in the early 90s. big big deal.
  • 16:45 - 16:54
    In fact it was so popular that it was utterly destroyed by all the consultants who invaded the realm and ruined what usecases were supposed to be.
  • 16:54 - 17:06
    You may recall if you remember that era that one consultant after another would publish on the Internet their own particular format for usecase.
  • 17:06 - 17:16
    And the format became all important. We had PDFs all out there, force you to fill in the blanks of a standard usecase form.
  • 17:16 - 17:23
    Anyway the fill in the name of the usecase and the input to the usecase and the precondition and postconditions
  • 17:23 - 17:30
    and primary actor and secondary actors and the (???) actor. What the hell is the (???) actor?
  • 17:30 - 17:38
    You had to fill in all the stuff and the whole problem of usecases became one of form instead of one of function.
  • 17:38 - 17:44
    And right about the peak of the era, the agile movement began.
  • 17:44 - 17:52
    And we stop talking about usecases and we started talking about stories and whole usecase thing fell on the floor. Nobody talked about it again.
  • 17:52 - 17:58
    And so I brought it up again and I read through the manual again, the book again.
  • 17:58 - 18:02
    And I remembered what Jacobson wrote.
  • 18:02 - 18:11
    Here is a usecase. Typical of the kind of usecase that Jacobson would have written.
  • 18:11 - 18:16
    If you notice that it has very little form.
  • 18:16 - 18:25
    Oh a little bit. It's got a name up there created order. Imagine this is a usecase for order processing system.
  • 18:25 - 18:32
    And it's got some input data like the customer id and customer contact information and the shipment destination.
  • 18:32 - 18:38
    Notice that I'm not supplying any details. I'm not saying what the customer Id is.
  • 18:38 - 18:40
    Whether it is a number or string, I don't care.
  • 18:40 - 18:48
    I'm not saying what the customer contact info is, I assume it's got a name and a date and a address and few other things. But I don't care.
  • 18:48 - 18:52
    I'm not trying to specify the detail here.
  • 18:52 - 18:55
    And then you've got the primary course.
  • 18:55 - 19:05
    And the primary course is the set of steps that computer will undertake to satisfy the usecase. these're the processing steps. (??)
  • 19:05 - 19:11
    And the first one is the order clerk issues the create order command that's actually not something the computer does.
  • 19:11 - 19:19
    And the second step is the system validates all the data. Notice I don't say how. Just validate somehow it doesn't matter.
  • 19:19 - 19:24
    Third step is system creates the order and determines the order Id.
  • 19:24 - 19:29
    I presume that some kind of database operation but I'm not going to say that here.
  • 19:29 - 19:35
    And then fourth step is at the system delivers order id to the clerk. Probably a web page but I'm not going to say that.
  • 19:35 - 19:40
    In fact, this whole usecase says nothing about the web.
  • 19:40 - 19:44
    This usecase would work no matter what the input output channel was.
  • 19:44 - 19:54
    I can make this usecase work on a console app, a desktop app, a web app, a service oriented architecture app, I Phone app it doesn't matter.
  • 19:54 - 20:00
    Because the usecase is agnostic, it doesn't care about the I/O channel.
  • 20:00 - 20:10
    Jacobson said you can take that usecase and turn it into object.
  • 20:10 - 20:20
    He called the object a control object. I've changed the name to an interactor to avoid confusion with Model View Controller.
  • 20:20 - 20:26
    Maybe I should have change the name to usecase. But I didn't. Interactor is what I've written here.
  • 20:26 - 20:38
    The interactor object implements the usecase, it takes as its input, the usecase's input, it delivers as its output, the usecase's output.
  • 20:38 - 20:46
    And it implements at least the high level. The rules, the processing steps of the usecase
  • 20:46 - 20:54
    Notice there's the caption below there. It says interactors have application specific business rules
  • 20:54 - 20:57
    There are two kinds of business rules
  • 20:57 - 21:06
    There are the kinds of business rules that are global, they are true no matter what the application is. They are application independent business rules
  • 21:06 - 21:12
    And then there are other business rules that are tied to the application you're writing
  • 21:12 - 21:22
    So for example, let's say that we've got an order entry application and an order processing application. Two completely different applications
  • 21:22 - 21:30
    Both of them might have an order object and that order object might have common business rules
  • 21:30 - 21:41
    Regardless of which of the two applications you're inside, but only one of those applications would have insert order usecase
  • 21:41 - 21:48
    So usecases are application specific, they're bounded to the particular application they're in
  • 21:48 - 21:57
    Business rules that are not application specific are bound to entity objects, some people would call these business objects
  • 21:57 - 22:01
    I don't like the term, entity objects that's what Jacobson called them as well
  • 22:01 - 22:11
    You put all of the application independent business rules into your entities and the interactor will control the entities.
  • 22:11 - 22:17
    Then you have to figure out the way to get the input and the output out of the usecase into another usecase
  • 22:17 - 22:24
    We do that in this case with interfaces. I have drawn these as object-oriented interfaces
  • 22:24 - 22:31
    And notice that the interactor uses one of the interfaces and derives from the other.
  • 22:31 - 22:38
    The one it derives from is the input interface. The one it uses is the output interface
  • 22:38 - 22:42
    Notice that the arrows point the same direction, that's important
  • 22:42 - 22:45
    We'll come to why that's important in a minute
  • 22:45 - 22:53
    So these are the three objects the Jacobson identified as part of his architecture for applications
  • 22:53 - 22:58
    Now let's trace this through, let's see how it works.
  • 22:58 - 23:03
    There's typical application. I've got some user out there that's that little man standing there
  • 23:03 - 23:11
    That's actual real person and that real person is interacting with system through some delivery mechanism.
  • 23:11 - 23:14
    Maybe it's the web, maybe it's not, who cares.
  • 23:14 - 23:26
    The person, user, pushes some buttons or type on the keyboard or does something that stimulates the system to accept data.
  • 23:26 - 23:32
    The delivery mechanism, maybe it's the web, maybe it's something else, it doesn't matter
  • 23:32 - 23:37
    Translates that into the creation of something that called request model.
  • 23:37 - 23:40
    A Request Model is a pure data structure.
  • 23:40 - 23:51
    A Plain Old .Net Object(POCO) or Plain Old Java Object(POJO), a raw data structure it has no idea where data came from there's no trappings of the web
  • 23:51 - 23:53
    If there's the trappings of the web anywhere
  • 23:53 - 23:57
    It's just a plain old data structure, no methods on it. No nothing.
  • 23:57 - 24:02
    Bunch of public elements in a data structure, it contains all the input data
  • 24:02 - 24:12
    That gets passed into an interface, the input boundary interface which the interactor derives from
  • 24:12 - 24:21
    The interactor receives the requests model and reads it and interprets it
  • 24:21 - 24:27
    And turns it into set of smaller commands which it sends to the entities
  • 24:27 - 24:33
    All the little business objects out there, it controls the dense of all the methods calls to the entities.
  • 24:33 - 24:42
    And once the job is done, then it reverses the flow. And it queries those entities and says, 'OK what happened to you?'
  • 24:42 - 24:48
    And there's the result of that it builds up yet another data structure called Result Model.
  • 24:48 - 25:01
    Result model is still just a plain old data structure, nothing knew about it, just an old plain .Net or Java object bunch of public fields no methods
  • 25:01 - 25:12
    That result model gets passed through the output boundary to the delivery mechanism where gets displayed somehow to the user.
  • 25:12 - 25:18
    That's the flow of just any other application.
  • 25:18 - 25:24
    Could you test that interactor?
  • 25:24 - 25:25
    must be easy wouldn't it?
  • 25:25 - 25:31
    Create the input data structure, invoke the interactor
    look at the output data structure
  • 25:31 - 25:33
    Do you have to the web server running to do that?
  • 25:33 - 25:41
    No, because the interactor, just plain old Java object or plain old .Net object, so all the data structure
  • 25:41 - 25:45
    Do you have to the database running to do that? Well you might. But we'll deal with that in a minute.
  • 25:45 - 25:51
    I can test this without the delivery mechanism in place at all
  • 25:51 - 25:56
    If my delivery mechanism is the web? I don't care! I don't have to have the web server running?
  • 25:56 - 25:58
    I don't have to test it with the web pages.
  • 25:58 - 26:07
    I can test the functioning of the system without going all the way from the inputs to the outputs
  • 26:12 - 26:14
    What about MVC?
  • 26:14 - 26:19
    Isn't MVC the thing we all supposed to doing?
  • 26:20 - 26:29
    What is the MVC stands for? Model View Controller. Who invented it?
  • 26:29 - 26:35
    That guy. Now I'm going to completely mispronounce his name. You can probably say it better than I
  • 26:35 - 26:42
    But I'm gonna call him Trygve Reenskaug. You can probably say it better than me.
  • 26:42 - 26:47
    I met him once. This is the guy who invented model view controller in late 1970s.
  • 26:47 - 26:50
    I met him once. I met him here at this conference two years ago.
  • 26:50 - 26:57
    I was up in speakers lounge and I was hunting for a power outlet
    And this old guy walks up to me and hands me a power outlet
  • 26:57 - 27:01
    I looked up and... Trygve Reenskaug!
  • 27:01 - 27:08
    And as he handed me the power outlet our fingers touched!
  • 27:08 - 27:13
    I haven' washed that hand. Trygve Reenskaug.
  • 27:13 - 27:19
    Some people came up and took their picture with me today. I'm a fan boy too.
  • 27:21 - 27:27
    In the early 80s and late 70s, Trygve Reenskaug came up with this structure called model-view-controller.
  • 27:27 - 27:30
    He did this in the Smalltalk platform.
  • 27:30 - 27:33
    And the idea behind it is very simple.
  • 27:33 - 27:37
    You've got a model object, the model object contains the business rules.
  • 27:37 - 27:41
    It does not know how it's displayed. It does not know where the input comes from
  • 27:41 - 27:48
    It's pure business rules nothing more. There's a controller down there. The controller handles all the input.
  • 27:48 - 28:00
    The job of the controller is to look at whatever the input device is, keyboard doesn't matter. And translate the actions of the user into commands to the model.
  • 28:00 - 28:01
    Then you've got the View.
  • 28:01 - 28:07
    And I've drawn the view with the funny double arrow. That's an Observer relationship.
  • 28:07 - 28:15
    The View registers with the model. And whenever the Model is changed it calls back to the View, telling the View to re-display.
  • 28:15 - 28:25
    The job of the View is to display or represent or somehow convey the contents of the Model to something else.
  • 28:25 - 28:35
    It works nicely on a graphical user interface. It also works just as well on a console device or service oriented architecture or any other kind of application you wish.
  • 28:35 - 28:41
    You have something that controls the input, (Controller)
    something that controls the process (Model)
    something that controls the output (View)
  • 28:41 - 28:51
    This probably the very first named design pattern ever, was meant to be used in the SMALL.
  • 28:51 - 29:02
    You would have a model view controller for a button. You would have a model view controller for a checkbox. You would have a model view controller for a text field
  • 29:02 - 29:05
    We did not have model view controller for a screen
  • 29:07 - 29:15
    Since those early days, this has been twisted and warped and turned because like anything in the software.
  • 29:15 - 29:24
    If it turned out to be a good idea, everyone else would copy it. And use the same name for something completely different and call it good.
  • 29:24 - 29:29
    This happened with OO
    It happened with structure
    It happened with Objects
    It happened with Agile
  • 29:29 - 29:38
    This happened with anything if the name connected with something good, then someone else will connect the name with their stuff and try call it good.
  • 29:38 - 29:44
    And that's what happened with MVC now. Nowadays we have these MVC frameworks
  • 29:44 - 29:50
    They don't look anything like that. They are not model view controller in the sense of Trygve Reenskaug's model view controller
  • 29:50 - 29:54
    They are something very different. In fact, they're kind of look like this.
  • 29:55 - 30:07
    Here you've got a bunch of controllers up there. Now the controller, if we think of the web, the controller are somehow activated by the web framework in the sky
  • 30:07 - 30:13
    The web framework in the sky, whatever it is, who cares, Rails, Springs God know what
  • 30:13 - 30:22
    will somehow route the complicated and horrible URLs that come from the web to a set of functions that we call Controller.
  • 30:22 - 30:27
    And it will pass into those controllers the arguments and the data came from the web.
  • 30:27 - 30:34
    And those controllers will then reach over and start yelling at the business objects, telling business objects what to do
  • 30:34 - 30:46
    Then they'll gather the data from the business objects and talk to the Views. And Views will then reach back into business objects and gather a bunch of data out of them and represent them.
  • 30:46 - 30:55
    And what you wind up with are business objects that get polluted with Controller like functions and with View like functions.
  • 30:55 - 31:05
    It's hard to know where to put the different function sometime they go into the business objects when they really shouldn't.
  • 31:09 - 31:14
    How can we deal with the output side?
  • 31:16 - 31:20
    Here I show you the interactor. The interactor has done its work
  • 31:20 - 31:32
    It's gathered the data from the entities the job of the usecases done. The response model has been built. We're about to pass the response model through the output boundary
  • 31:32 - 31:38
    And what implements that output boundary? Something called Presenter.
  • 31:38 - 31:45
    The job of the presenter is to take that response model which, remember, is a pure data structure.
  • 31:45 - 31:52
    And translate it into yet another pure data structure, which we would call a View Model.
  • 31:52 - 32:04
    The view model is a model of the output, the representation of the output. It still a data structure.
  • 32:04 - 32:11
    But if there is a table on the screen, there will be a table in that data structure
  • 32:11 - 32:17
    If there is a text field on the screen, there'll be a text field in that data structure
  • 32:17 - 32:28
    If the numbers on the screen need to be trimmed to two decimal places, there will be TrimToTwoDecimalPlaces and ConvertIntToStrings in the view model.
  • 32:28 - 32:38
    If they have parenthesis around them if they're negative those parenthesis will have been put on them by the Presenter and put into the View Model.
  • 32:38 - 32:43
    If there are menu items, names of those menu items are in the View Model.
  • 32:43 - 32:53
    If some of those menu items need to be grayed out because they're inactive, there are booleans in the view model that tell you that they should grayed out
  • 32:53 - 33:05
    Anything displayable is represented in the view model data structure in a displayable but still abstract way.
  • 33:05 - 33:08
    And then that get feds the View.
  • 33:08 - 33:16
    And View is stupid. View doesn't have anything to do with, just takes all the fields from the View Model. Put somewhere they have to go. Boom Boom Boom
  • 33:16 - 33:21
    No processing, No if statement, it might be a while loop to load up a table. But that's about it.
  • 33:21 - 33:30
    The View is too dumb to worry about we don't usually even bother about testing the view. Because we gonna look at it with our eyes on it anyway.
  • 33:30 - 33:33
    Can you test that Presenter?
  • 33:33 - 33:38
    Yeah! You handed it the data structure with response model. And You look to get the View Model data structure out.
  • 33:38 - 33:44
    You can test that Presenter. Do you need the webserver up and running to test Presenter?
  • 33:44 - 33:49
    No, You can test all the stuff without webserver running.
  • 33:49 - 33:53
    You don't have to fire up Spring or whatever God knows all the container You've got
  • 33:53 - 33:56
    You don't know how to fire up all this goop.
  • 33:56 - 34:00
    You test all this stuff just like the little old objects
  • 34:00 - 34:07
    And by the way that's a goal. You wanna test as much as you can test without firing up anything.
  • 34:07 - 34:13
    You don't have to start the server, start that server, start this thing, start this thing which takes 30 seconds to a minute.
  • 34:13 - 34:21
    You don't have to any of that. You want to just be able to run your test Just like that boom boom boom boom, fast as you can.
  • 34:23 - 34:26
    There's the whole piece.
  • 34:26 - 34:32
    From the interactor out, you can see the interactor takes data in from the request model through the input boundary
  • 34:32 - 34:38
    delivers data through the output boundary through the response model into the Presenter
  • 34:38 - 34:49
    And now look at that black line. That black line is the line that divides the delivery mechanism from the application.
  • 34:49 - 34:55
    And notice that every arrow crosses that black line pointing towards the application.
  • 34:55 - 35:00
    The applications knows nothing about the controller or the presenter.
  • 35:00 - 35:05
    It knows nothing about the web, it knows nothing about what that I/O channel is.
  • 35:05 - 35:11
    The I/O channel knows about the application, the applications does not know about the I/O channel.
  • 35:11 - 35:21
    If you are to put them in the separate Jar files, there would be no dependence from the application jar file upon the web jar file
  • 35:21 - 35:30
    And that also ways to go. You'd like to be able to put them in the separate Jar files. So that you could have a Jar file for the web and a jar file for your application
  • 35:30 - 35:34
    And maybe another Jar file for some other I/O mechanism.
  • 35:34 - 35:39
    And the way that you would change I/O mechanism is simply swap out the jar files.
  • 35:39 - 35:50
    Think of the I/O mechanism, the web, as a plug-in. How many of you use .Net Sharp isn't it?
  • 35:50 - 35:55
    You guys all .Net are you? Who's .Net?
  • 35:55 - 36:04
    What IDE do you use? Do you have any plug-ins? So a plug-in
  • 36:06 - 36:15
    Which of the two authors, the author of the IDE and the author of the Plug-in. Which of the two authos knows about the other?
  • 36:17 - 36:26
    The plug-in authors know about the IDE authors. The IDE authors don't know anything about the plug-in authors.
  • 36:26 - 36:28
    Don't care.
  • 36:28 - 36:36
    Which of the two can harm the other? Can the plug-in author harm VisualStudio?
  • 36:36 - 36:43
    Who's using Resharper? Yeh. Can the Resharper guys, JetBrains guys can they harm VisualStudio?
  • 36:43 - 36:47
    - (Listeners) Yes, yes
    - (Robert Martin) Well, they can break it.
  • 36:47 - 36:53
    But can they harm it in the way that the authors of VisualStudio must respond to?
  • 36:53 - 36:59
    The software developers at Microsoft will they ever respond to JetBrains?
  • 36:59 - 37:02
    No, they don't care about JetBrains.
  • 37:02 - 37:10
    Can the developers at Microsoft force the developers at JetBrain to respond to them?
  • 37:10 - 37:14
    Yeh, Big time!
  • 37:14 - 37:18
    Now, think about that in your application's point of view.
  • 37:18 - 37:26
    Which parts of your application do you want to be protected from other parts?
  • 37:26 - 37:35
    Which parts do you want to be forced to respond the changes in the other and which ones do you not want to be forced to change in response to the other?
  • 37:35 - 37:39
    And the answer to the ought to be very very clear.
  • 37:39 - 37:45
    You would like to protect your business rules from changes to the web.
  • 37:45 - 37:50
    You don't wanna protect the web from changes to the business rules.
  • 37:50 - 38:00
    But changes on the web side should have no affect at all on the business rules side and that's what the architecture guarantees you.
  • 38:00 - 38:07
    All those dependencies point inward towards the application. Keep that in mind. That is the plug-in architecture.
  • 38:08 - 38:12
    Which leads us to the database.
  • 38:15 - 38:18
    What about the database?
  • 38:20 - 38:23
    Is that your view of the database?
  • 38:24 - 38:32
    Do you think of the database is the great god in the center with little minions around outside being applications?
  • 38:32 - 38:38
    Does anybody have a job function of DBA? Do we have DBAs in the room?
  • 38:38 - 38:39
    Aha I'm safe. Good.
  • 38:39 - 38:49
    Anybody know about the DBA? Rolled it over the applications. Panned out the schema. Make sure the database is right.
  • 38:49 - 38:52
    Is this how you think about the database?
  • 38:53 - 38:55
    Because here's my point.
  • 38:55 - 38:57
    The Database is a detail!
  • 38:57 - 39:01
    It's not architecturally significant!
  • 39:01 - 39:05
    The database is a bucket of bits!
  • 39:06 - 39:10
    It is not an architecturally significant element of you system.
  • 39:10 - 39:13
    It has nothing to do with business rules.
  • 39:13 - 39:17
    God help you if you are putting business rules in the stored procedure.
  • 39:17 - 39:26
    What goes in the stored procedure are enhanced queries, validations, integrity checks, but not business rules.
  • 39:30 - 39:33
    Why do we have databases?
  • 39:34 - 39:41
    Where did this whole database thing come from? Why is there Oracle?
  • 39:46 - 39:49
    Where did we store all that data?
  • 39:49 - 39:53
    We stored it on spinning disks. Is anybody written a disk driver?
  • 39:53 - 39:58
    Anybody written a software that controls memory in and out of spinning disk?
  • 39:58 - 40:07
    Nobody! Oh gosh. Oh... Yeah! disk driver!
  • 40:07 - 40:10
    What? Diskette? That's good enough!
  • 40:10 - 40:15
    So getting data in and off of a disk is hard. Why is it hard?
  • 40:15 - 40:18
    Because of the way the data is organized on the disk.
  • 40:18 - 40:22
    The way the data is organized on the disk in the circular tracks.
  • 40:22 - 40:26
    The circular tracks go around the surface of the platter. There can be many platters.
  • 40:26 - 40:35
    There are heads that move in and out to find the track, so you've got to move the head to the right track.
  • 40:35 - 40:39
    Then the disk spins around and you've got to read the data off the disk.
  • 40:39 - 40:47
    You try get to the sector you want. There might be fifty of sixty sectors around the surface of a track. Each of the sectors might have 4k bytes.
  • 40:47 - 40:52
    So you gotta wait for the disks spin around until your sector comes then you gotta read the sector.
  • 40:52 - 40:57
    And then you go into that sector and find the byte you want.
  • 40:57 - 41:01
    That's a pain. And it's slow.
  • 41:01 - 41:05
    And if you don't optimize it can take forever to get anything in and off the disk!
  • 41:05 - 41:14
    So we wrote the systems that optimize for that particular problem. We called them databases.
  • 41:15 - 41:18
    But somethings happened.
  • 41:18 - 41:28
    See my lap top there? My lap top has half of terabyte of Solid State Memory. Doesn't have a disk. That shouldn't be a surprise to you.
  • 41:28 - 41:31
    Is anybody have disk in the room?
  • 41:31 - 41:34
    Is there a spinning disk in this room?
  • 41:34 - 41:37
    Oh my god, really?
  • 41:37 - 41:43
    Huh, you know, nowadays we don't even think about spinning disks anymore. We think about Solid State Memory.
  • 41:43 - 41:50
    Oh we think back in the server room. There's probably spinning disks. But, there are going away too.
  • 41:51 - 41:56
    You watch over next few years. spinning disks begin to disappear. Everything gets replaced with RAM.
  • 41:56 - 42:00
    And I said RAM, didn't I?
  • 42:00 - 42:04
    RAM is directly addressable at a byte level.
  • 42:04 - 42:14
    What we are approaching is a virtually infinite amount of directly addressable RAM that is persistent.
  • 42:14 - 42:18
    That's where we are going to be storing our data.
  • 42:18 - 42:28
    And if that's where we are going to be storing our data, why in hell would we want to use SQL to access it?
  • 42:28 - 42:32
    SQL's pain. Tables are a pain.
  • 42:32 - 42:37
    Wouldn't you rather be following pointers around when you rather looking things up in hash tables?
  • 42:37 - 42:45
    Isn't that what you do anyway? You read all the tables into memory and then put the data into better organizations You can actually use it?
  • 42:45 - 42:49
    What if we just left it in that format that we want to use it?
  • 42:49 - 42:53
    If I were Oracle I would be scared to death.
  • 42:53 - 42:57
    Because the reason for my existence is disappearing out from underneath.
  • 42:57 - 43:03
    The notion of a big database system is beginning to go away.
  • 43:05 - 43:10
    How can I protect my application from this detail?
  • 43:10 - 43:19
    This detail of database tends to dominate everything and I can protect it the same way I protected my application against the web.
  • 43:19 - 43:23
    I draw another one of those nice big heavy black lines.
  • 43:23 - 43:30
    And I make sure all the dependencies cross that line going inward towards the applications.
  • 43:30 - 43:36
    I make the database a plug-in to the application.
  • 43:36 - 43:39
    So that I can swap out Oracle with MySQL
  • 43:39 - 43:43
    or I can yank out MySQL and put in CouchDB
  • 43:43 - 43:47
    or I can take out CouchDB and put in Datomic or whatever I wish.
  • 43:47 - 43:50
    I can plug in the database.
  • 43:50 - 43:57
    You may never change the database but it's nice to be able to. Even if you don't have to.
  • 43:57 - 44:01
    How do we do it? Well, fairly straight forward, there's another interface up there.
  • 44:01 - 44:03
    I called it here the Entity Gateway.
  • 44:03 - 44:10
    You probably have one per entity and the methods in the gateway are all the query methods.
  • 44:10 - 44:14
    Anything you might query, there's function for, method for
  • 44:14 - 44:19
    You implement that method down in the entity gateway implementation below the line.
  • 44:19 - 44:23
    And that implementation uses the database whatever it is.
  • 44:23 - 44:30
    Notice that no part of the database manages the leak into the application.
  • 44:30 - 44:40
    Where the entity objects come from. Well entity objects are probably fetched out of the database although got knows what crazy way they've been spread out in the tables.
  • 44:40 - 44:44
    The implementation of entity gateway will gather the data together.
  • 44:44 - 44:48
    Create entity objects and then pass them across the line.
  • 44:48 - 44:53
    So once you get them above the line, they are real entity objects.
  • 44:55 - 45:00
    Guys using something like Hibernate? Some ORM tool?
  • 45:00 - 45:02
    Who's using something like that?
  • 45:02 - 45:07
    Where would that be in this diagram?
  • 45:07 - 45:10
    In the implementation! Below the line!
  • 45:10 - 45:16
    No part of that ORM tool would be known above the line.
  • 45:16 - 45:22
    Are You using those funny little annotations and attributes in business objects? Get them out of your business objects.
  • 45:22 - 45:25
    You dont' want your business objects to know that there are built by Hibernate.
  • 45:25 - 45:32
    Let them be built below the line by somebody who's polluted already by the database concept.
  • 45:32 - 45:36
    Keep your business objects pure. Why?
  • 45:38 - 45:41
    What's an object?
  • 45:43 - 45:45
    I've got time for this.
  • 45:47 - 45:54
    What's an object? An object is a set of public methods
  • 45:54 - 46:01
    And well you are not allowed to know the rest, are you?
  • 46:01 - 46:05
    There might be data in there. But you're not allowed to see it. It's all private, isn't it?
  • 46:05 - 46:11
    From you point of view, object is bunch of methods. Not a bunch of data.
  • 46:11 - 46:14
    And object is a bunch of methods.
  • 46:14 - 46:17
    An object is about behavior.
  • 46:17 - 46:21
    An object is about business rules.
  • 46:21 - 46:23
    It is not about data.
  • 46:23 - 46:26
    We presume there's data in there somewhere, but we don't know where.
  • 46:26 - 46:30
    And we don't know what formats in it. We don't want to know.
  • 46:30 - 46:33
    What is a data structure?
  • 46:33 - 46:41
    A data structure is a grouping of well known data elements. Public. Visible to everybody.
  • 46:41 - 46:43
    And there's no methods in them.
  • 46:43 - 46:45
    Data structures don't have functions.
  • 46:45 - 46:47
    These two things are exact opposite of each other.
  • 46:47 - 46:55
    A data structure has visible data and no methods. An object has visible functions and no visible data.
  • 46:55 - 46:56
    Precisely the opposite.
  • 46:56 - 47:00
    There's no such thing as an ORM.
  • 47:00 - 47:03
    Object relational mapper? Can't do it.
  • 47:03 - 47:10
    Because what comes out of database is a data structure and you cannot map a data structure to an object.
  • 47:10 - 47:12
    Cause they are completely different things.
  • 47:12 - 47:20
    What's happening here is that the data needed by entities gets put somewhere. God knows where.
  • 47:20 - 47:27
    And somehow magically passed to an entity that uses it somehow. And I don't care how.
  • 47:27 - 47:31
    Those entities are not constructed by Hibernate.
  • 47:31 - 47:38
    Probably those entities use bunch of little data structures that Hibernate did construct but I don't care how.
  • 47:38 - 47:45
    I don't want any knowledge of Hibernate or any other framework to cross that black line.
  • 47:45 - 47:48
    Stuff below the line can be polluted.
  • 47:48 - 47:55
    Above the black line, those are my family jewels. I'm gonna keep them protected.
  • 47:55 - 48:03
    Those are my business rules. I'm not going to allow my business rules to be polluted with frameworks.
  • 48:03 - 48:10
    Frameworks. We like our frameworks. We think they're cool.
  • 48:10 - 48:15
    We think frameworks save us a lot of time and they do.
  • 48:15 - 48:22
    But the authors of frameworks entice us to bind to them.
  • 48:22 - 48:26
    They offer us base classes for us to inherit from.
  • 48:26 - 48:32
    When you inherit from a base class, you marry that class.
  • 48:32 - 48:40
    You bind yourself strongly to that base class. There's no relationship stronger than inheritance.
  • 48:40 - 48:47
    So by deriving from someone else's base class, you're making a huge commitment to them.
  • 48:47 - 48:52
    But they, on the other hand, are not making any kind of commitment to you.
  • 48:52 - 48:55
    So it's an asymmetrical relationship.
  • 48:55 - 49:02
    The framework author gets the benefit of your commitment. But the framework author makes no commitment to you at all.
  • 49:02 - 49:07
    I leave you to make that comparison to yourself.
  • 49:07 - 49:12
    A wise architect does not make that binding.
  • 49:12 - 49:21
    A wise architect looks at the framework cynically. Looks at and says that framework ought to screw me.
  • 49:21 - 49:26
    That framework wants me to bind to it. And I don't think I'm going to.
  • 49:26 - 49:31
    I think I'm gonna put boundaries between my business rules and that frameworks.
  • 49:31 - 49:39
    So that my business rules are not forever tied to Hibernate or Spring. God know what.
  • 49:39 - 49:44
    I'll use the framework. And I'll use the framework carefully.
  • 49:44 - 49:50
    Because the author of the framework does not have my best interest at heart.
  • 49:56 - 50:03
    Long ago, my son and I and several other people wrote a tool called Fitnesse.
  • 50:03 - 50:07
    Is anybody use Fitnesse? Oh bunch of you, good.
  • 50:07 - 50:13
    Fitnesse is a tool for writing customer acceptance test.
  • 50:13 - 50:18
    It's based on a Wiki and that's really all you need to know it's based on a Wiki.
  • 50:18 - 50:19
    Who invented Wiki?
  • 50:19 - 50:22
    Ward Cunningham. Who's Ward Cunningham?
  • 50:22 - 50:27
    Guy invented Wiki. Ah~ He's a lot more than that.
  • 50:27 - 50:35
    Ward Cunningham is one of those Gurus of Gurus. All the Gurus know who Ward Cunningham is.
  • 50:35 - 50:40
    All the guys who go around speaking at conferences, like me, we all know who Ward Cunningham is.
  • 50:40 - 50:42
    And we review him from on high.
  • 50:42 - 50:46
    He was the guy made phone call to Eric Gamma
  • 50:46 - 50:50
    Said "You know Eric, you gotta write a book called design patterns."
  • 50:50 - 50:58
    This is the guy mentored Ken Beck. Taught him things like Pair Programming and Test Driven Development and Agile Development.
  • 50:58 - 51:07
    Ward Cunningham is a one of those guys, if you know a lot about the history of software. You think "Wow he had his hands in everything!"
  • 51:07 - 51:12
    Fitnesse is based on two inventions of Ward, the Wiki and Fit.
  • 51:12 - 51:16
    I'm not going to describe Fit. I'll describe Wiki however.
  • 51:16 - 51:25
    My son and I and bunch of other folks decided to write this in Java about 12 years ago. 13 years ago something like that.
  • 51:25 - 51:28
    We knew we wanted make a Wiki.
  • 51:28 - 51:35
    And so we thought "Well we got a place to store the pages, let's store them in a database and what database would that be?"
  • 51:35 - 51:42
    Well back in those days the only opensource database was MySQL. So we decided put everything in MySQL.
  • 51:43 - 51:51
    And we were about to go fire up MySQL and start building a schema and somebody said.
  • 51:51 - 51:54
    "You know we don't really have to do that. Right yet"
  • 51:54 - 51:59
    "I mean we will later but not right now because we can get away right now with another problem"
  • 51:59 - 52:03
    And that problem was translating Wiki text to HTML. That's what Wiki does.
  • 52:03 - 52:07
    Takes the funny text you typed into the Wiki and turns it into HTML.
  • 52:07 - 52:10
    And there was a lot of that translation that we needed to do.
  • 52:10 - 52:14
    So about 3 month we just forgot about the database altogether.
  • 52:14 - 52:21
    And we translated Wiki text to HTML. We needed an object for this which we called WikiPage.
  • 52:21 - 52:23
    You can see it here.
  • 52:23 - 52:30
    We created an abstract class named WikiPage and we implemented it with something called MockWikiPage.
  • 52:30 - 52:37
    The methods of WikiPage had database like funtions such as Load and Save.
  • 52:37 - 52:40
    But they were unimplemented. The didn't do anything.
  • 52:40 - 52:43
    And for about three months we worked that way.
  • 52:43 - 52:49
    Once we had all the translation done. Then we said "Well it's time to fire up the database."
  • 52:49 - 52:52
    "Cause now we need to actually store these pages somewhere"
  • 52:52 - 52:55
    And somebody said "Well, we don't need to do that yet."
  • 52:55 - 53:00
    "Because what we could do instead is take this pages and store them in a hash tables in RAM."
  • 53:00 - 53:03
    "I mean we don't really need to store them on disk yet, do we?"
  • 53:03 - 53:06
    The answer to that was no. Cause all we were doing was writing unit test anyway.
  • 53:06 - 53:15
    So we decided to create a another version of the Wiki page called the InMemoryPage which stored all the data in hash tables.
  • 53:15 - 53:17
    And we continued to work for a year.
  • 53:18 - 53:22
    Continuing to write more and more Fitnesse keeping all the data in memory.
  • 53:22 - 53:24
    We actually got all of Fitnesse working.
  • 53:25 - 53:27
    Without ever putting it into a disk.
  • 53:27 - 53:32
    And it was very cool because all the test went really fast. No database.
  • 53:32 - 53:39
    On the other hand it was frustrating because we would created a bunch of tests and shut the computer down and then all be gone.
  • 53:39 - 53:45
    So it's some point we finally said "Well now it's the time for database, let's fire up MySQL."
  • 53:45 - 53:47
    And Michael Feathers was there at that time.
  • 53:47 - 53:50
    And Michael said "Well you don't really have to fire up MySQL yet."
  • 53:50 - 53:59
    "All you really need is persistence. And you can get that persistency really cheaply by taking the hash tables to be written into flat files."
  • 53:59 - 54:07
    And we thought that's kind of ugly but it'll work for the time being. And then later on we'll switch it all over MySQL. So we did that.
  • 54:07 - 54:11
    And for another 3 months we continued to develop more and more about Fitnesse.
  • 54:11 - 54:16
    And that was kind of cool. Cause we could take on the road. We could show it to people. We could save pages.
  • 54:16 - 54:18
    Started work like real Wiki.
  • 54:19 - 54:28
    About 3 months after that we said "We don't need that database"
  • 54:29 - 54:32
    "It's working fine! Flat files are fast enough."
  • 54:32 - 54:34
    "Works okay, that way."
  • 54:34 - 54:39
    We took that highly significant architectural decision and pushed it off to the end of planet.
  • 54:39 - 54:44
    We never put that database in. That's not quite true actually. Somebody else did.
  • 54:44 - 54:50
    A customer of ours came along little latter and said "I gotta have the data in database."
  • 54:50 - 54:52
    We said "But why? It's working fine in the flat file"
  • 54:52 - 54:59
    He said "Corporate policy, all corporate assets must be in a database."
  • 54:59 - 55:04
    I don't know who they'd been talking to. But these database salesman were pretty convincing.
  • 55:04 - 55:12
    So, we said "Well Look. If you really needed it in a database."
  • 55:14 - 55:24
    "Here's this structure all you have to do is create a new derivative called MySQL page. And everything ought to work fine."
  • 55:24 - 55:27
    And he came back a day latter and the whole thing running MySQL.
  • 55:27 - 55:31
    We used to ship that as a plug-in but nobody ever used it so we stopped.
  • 55:32 - 55:38
    Here's an architectural decision that we deferred and deferred and delayed and delayed.
  • 55:38 - 55:41
    We delayed right up to the end of project. Ne never did it.
  • 55:41 - 55:45
    Something that we thought we had to do it first, we never did it.
  • 55:45 - 55:49
    That leads to the final principle.
  • 55:51 - 56:00
    A good architecture is an architecture that allows major decisions to be delayed! Deferred!
  • 56:00 - 56:05
    The goal of an architect is to not make decisions.
  • 56:05 - 56:13
    To delay those decisions as long as possible so that you have the most information with which to make them.
  • 56:13 - 56:22
    You structure design and the high level structure of your code so that all these high level decisions can be pushed off.
  • 56:22 - 56:29
    Don't tell me that the architecture of your application is a bunch of frameworks.
  • 56:29 - 56:36
    "What's the architecture of your application? Yeah, we're using a SQL server and MVVM and blah.. "
  • 56:36 - 56:37
    You're not telling me anything.
  • 56:37 - 56:41
    You're telling me the tools.
  • 56:41 - 56:43
    That's not the architecture of your application.
  • 56:43 - 56:46
    The architecture of your applications are the usecases.
  • 56:46 - 56:50
    And you want your usecases to not know about those tools.
  • 56:50 - 56:55
    You wanna be able to defer the use of those tools for as long as possible.
  • 56:55 - 57:02
    You should be able to have the whole application running without ever firing up a database, without ever firing up the web.
  • 57:02 - 57:07
    Or maybe you fire up some gunky little web thing that you can toast together in a day or two.
  • 57:07 - 57:12
    Just so that you can see some pages without firing up some gigantic framework.
  • 57:12 - 57:17
    Maybe you fire up some dumb little database thing just so that you can see some persistence running.
  • 57:17 - 57:24
    Without ever having a license of Oracle and all the nonsense you have to go through to get that running.
  • 57:25 - 57:34
    Next time you have a application to write, think about what you can delay.
  • 57:38 - 57:48
    The application of a system should a plug-in architecture. The architecture of a system should be a plug-in architecture.
  • 57:48 - 57:55
    Well all of the details like the UI, the databse, the frameworks plug in to the usecases.
  • 57:55 - 57:58
    Which are the real core of your application.
  • 58:00 - 58:04
    Now of course, customers are gonna wanna see web pages.
  • 58:04 - 58:10
    Okay, you can stil make a plug-in architecture and show them web pages running.
  • 58:11 - 58:13
    You don't have to make a lot of commitments to the frameworks.
  • 58:13 - 58:17
    You don't have to make a lot of commitments to the web framework.
  • 58:17 - 58:19
    You can probably put something simple up it first.
  • 58:19 - 58:26
    Or if you want actually use a real framework, fine go ahead. But maintain the plug-in structure.
  • 58:26 - 58:29
    So that at a moment's notice you can unplug it and plug something else in.
  • 58:31 - 58:35
    And that probably brings to me the end of my talk.
  • 58:36 - 58:39
    I already talked about that earlier. (TDD)
  • 58:42 - 58:45
    So thank you all very much. are there any questions?
  • 58:48 - 58:51
    Very difficult to see, so I'm gonna come down here.
  • 58:55 - 58:57
    Oh that doesn't help at all.
  • 58:57 - 59:01
    Okay, anybody have any questions?
  • 59:01 - 59:04
    You gonna have to like hollow. Because I won't be able to see your hands up.
  • 59:04 - 59:05
    Yep.
  • 59:05 - 59:12
    (Someone is asking a question)
  • 59:12 - 59:21
    So I'm speculating the demise of Oracle and relational databases. What do I suggest to will replace them?
  • 59:21 - 59:24
    What an interesting question!
  • 59:24 - 59:31
    It could be nothing more than RAM. Why do you need anything to replace them?
  • 59:31 - 59:37
    If you gonna organize the data in RAM and if that RAM is persistent, what else do you need?
  • 59:37 - 59:39
    Oh but let's say you need something.
  • 59:39 - 59:41
    Okay what might it look like?
  • 59:42 - 59:46
    Well, who's heard of the CQRS?
  • 59:46 - 59:48
    Oh yeah, few of you.
  • 59:48 - 59:50
    CQRS, what an interesting idea?
  • 59:50 - 59:55
    If we have infinite amount of high speed memory. High speed RAM.
  • 59:55 - 59:58
    Or maybe it's even disk but who cares.
  • 59:58 - 60:02
    Why would we store the state of anything.
  • 60:02 - 60:05
    Why wouldn't we simply store the transactions?
  • 60:05 - 60:12
    Instead of storing a bank account, Why wouldn't we store the transactions that caused us to create the bank account.
  • 60:12 - 60:19
    The transactions that forced us to change the name in the bank account or the address of the bank account or the balance in the bank account.
  • 60:19 - 60:23
    Why wouldn't we store the transactions and reconstruct the state.
  • 60:23 - 60:26
    And you say to yourself "Well it will take a lot of time"
  • 60:26 - 60:29
    Yeah, but we've lots of processing power.
  • 60:29 - 60:35
    We can do that now, we have almost infinite amount of processing power and almost infinite amount RAM.
  • 60:40 - 60:44
    Why wouldn't we store just the events?
  • 60:44 - 60:46
    And I think that's an interesting idea.
  • 60:46 - 60:53
    If we store just events, then we would never delete anything.
  • 60:53 - 60:56
    We would never update anything.
  • 60:56 - 60:59
    You know CRUD? Create. Read. Update. Delete?
  • 60:59 - 61:05
    We'd loose the last 2 letters there. All our applications would be CR.
  • 61:05 - 61:09
    Create and Read. We would never update. We would never delete.
  • 61:09 - 61:14
    And when you don't update and you don't delete you don't need transactions.
  • 61:14 - 61:17
    There can't be any concurrent update problems if you're not updating.
  • 61:17 - 61:20
    That's interesting!
  • 61:20 - 61:25
    Are there frameworks out there that allow you to do things like that? There are.
  • 61:25 - 61:27
    There are number of them out there.
  • 61:27 - 61:32
    That are write only databases. Write once and read many times.
  • 61:33 - 61:35
    You can find them on the web. I'm not gonna tell you the names right now.
  • 61:35 - 61:38
    But you can go out there and look for them. There are out there.
  • 61:38 - 61:40
    You might replace them something like that.
  • 61:40 - 61:46
    You might replace them with Couch or Mongo. Or you might create some other thing.
  • 61:46 - 61:52
    It really doesn't matter. You don't have to have some massive vendor offering.
  • 61:52 - 61:54
    From some gigantic company in the sky.
  • 61:54 - 61:59
    That blesses you and says "Yes son, you may use my database system."
  • 62:00 - 62:03
    Maybe you can just make your own. Not that hard.
  • 62:03 - 62:05
    Anybody else?
  • 62:08 - 62:09
    Yeah, that actually helps a lot.
  • 62:09 - 62:12
    Okay, anybody else with questions?
  • 62:15 - 62:27
    (Someone is asking a question)
  • 62:27 - 62:32
    Differing decisions does not work very well when..
  • 62:34 - 62:42
    When you have a family? (People laughing)
  • 62:44 - 62:47
    You mean in general. There are decisions you can differ.
  • 62:47 - 62:50
    For example, what language we gonna write this thing in?
  • 62:50 - 62:53
    You gonna have to make that decision pretty early.
  • 62:53 - 62:56
    Right? Cause you know you gotta write some.
  • 62:56 - 63:02
    The fact that you're going to have a database, probably something you gonna have to make a decision on pretty early.
  • 63:02 - 63:07
    The fact that it's gonna be a web application, well you probably have to make that fairly early.
  • 63:07 - 63:09
    You have to commit to framework. No.
  • 63:10 - 63:14
    A family vacation that's what you were saying here.
  • 63:14 - 63:23
    We could plan out where we were going. Would we have to also plan out which car we would use?
  • 63:23 - 63:31
    If we're planning a six month in advance, we might decide buy whole new car just for the heck of it?
  • 63:31 - 63:36
    Maybe our car break down in the middle. Or before we go on the vacation.
  • 63:36 - 63:43
    The car itself is just a vehicle, it doesn't matter as long as our luggage fits in it. And our family.
  • 63:43 - 63:45
    We can still go on the vacation.
  • 63:45 - 63:54
    The database system is like the car. We don't need to make that decision as part of vacation plan.
  • 63:56 - 63:59
    That one can be differed to the last minute.
  • 63:59 - 64:04
    You could buy a new car the last minute, the day before you decide to go on vacation.
  • 64:04 - 64:06
    And why would you do that?
  • 64:06 - 64:09
    You might have gotten a race. You might have more money.
  • 64:09 - 64:12
    You might have a baby. Need more space.
  • 64:12 - 64:18
    A lot of reason you might wanna buy that car at the last minute.
  • 64:19 - 64:21
    Anybody else?
  • 64:22 - 64:24
    Yeah, way back there.
  • 64:24 - 64:29
    (Someone is asking question)
  • 64:29 - 64:32
    How do you deal with legacy architecture?
  • 64:32 - 64:35
    Okay, that's gonna take me more than a minute.
  • 64:36 - 64:40
    So I'm gonna use one word to answer that question and I'll explain that word.
  • 64:40 - 64:42
    Incrementalism.
  • 64:42 - 64:48
    Everybody faced with legacy code wants to throw it away and write it over.
  • 64:48 - 64:50
    Please don't do this.
  • 64:51 - 64:56
    They generally fails, Horribly you'll spend tremendous amount of money and waste a load of time.
  • 64:56 - 64:58
    Take little bits of it.
  • 64:58 - 65:01
    And rewrite those tiny little bits one at a time.
  • 65:01 - 65:04
    And get them working one little bit at a time.
  • 65:04 - 65:08
    That will leave you with a patch work. But the patch work will be cleaner than the original.
  • 65:08 - 65:12
    And then start over and start re-implementing the patch work.
  • 65:12 - 65:17
    Gradually cleaning it making it better and better. It'll take you long time, a lot of effort.
  • 65:17 - 65:20
    You wanna do that while you also adding new features.
  • 65:20 - 65:24
    In fact, that's just generally cleaning your code.
  • 65:24 - 65:28
    Please don't try the big re-design. You'll get hurt.
  • 65:28 - 65:33
    Thank you all for your attention. I'll see you another time.
Title:
Robert C. Martin - Clean Architecture and Design
Description:

more » « less
Video Language:
English
Duration:
01:05:41

English subtitles

Revisions