< Return to Video

RailsConf 2014 - Modeling on the Right Side of the Brain by Nicholas Henry

  • 0:17 - 0:21
    NICHOLAS HENRY: Good morning.
  • 0:21 - 0:24
    How many of you have read or heard of the
    book,
  • 0:24 - 0:26
    Drawing on the Right Side of the Brain?
  • 0:26 - 0:29
    OK. We've got a, we've got a few people.
  • 0:29 - 0:30
    All right. Excellent.
  • 0:30 - 0:32
    For those who don't know, this book was authored
  • 0:32 - 0:37
    by Betty Edwards. It was originally published
    in 1979,
  • 0:37 - 0:41
    and this latest edition was published in 1999.
    And
  • 0:41 - 0:43
    it dispelled this myth that drawing was a
    talent
  • 0:43 - 0:46
    that you were born with. And it's actually
    a
  • 0:46 - 0:48
    skill that can be learned.
  • 0:48 - 0:53
    Now, one of these skills is viewing negative
    space.
  • 0:53 - 0:55
    The idea that you draw the ob- you don't
  • 0:55 - 0:58
    draw the object, but you draw the spaces in
  • 0:58 - 1:01
    between the object. And this tricks the brain.
    It
  • 1:01 - 1:03
    switches the brain from a left mode to a
  • 1:03 - 1:06
    logical think- from a logical thinking mode
    to a
  • 1:06 - 1:09
    right-brain or a perceptual mode.
  • 1:09 - 1:12
    And the benefit of this is when we're making
  • 1:12 - 1:16
    logical decisions, but we make bad perceptual
    decisions. Great
  • 1:16 - 1:19
    example is this chair. If you look at the
  • 1:19 - 1:22
    chair, you'll see the legs are quite thin.
    And
  • 1:22 - 1:24
    logically you think, man, if I sit on that
  • 1:24 - 1:26
    chair, that's not gonna hold. That's not gonna
    support
  • 1:26 - 1:29
    a person. And so logically would go, would
    increase
  • 1:29 - 1:31
    the size of those legs, and we end up
  • 1:31 - 1:33
    distorting the, the picture.
  • 1:33 - 1:40
    Betty Edwards describes drawing as five, sorry,
    she describes
  • 1:40 - 1:44
    drawing as a global skill, consisting of five
    basic
  • 1:44 - 1:49
    skills. And she describes these skills as
    perceptual skills.
  • 1:49 - 1:53
    The ability to correctly and efficiently understand
    what is
  • 1:53 - 1:55
    being seen.
  • 1:55 - 1:57
    I'm Nicholas Henry, and I'd like to welcome
    you
  • 1:57 - 2:00
    to my talk, Modeling on the Right Side of
  • 2:00 - 2:02
    the Brain, where I'll introduce you to the
    five
  • 2:02 - 2:06
    basic skills of object-modeling. We will explore
    using color
  • 2:06 - 2:10
    and patterns to help you visualize and communicate
    and
  • 2:10 - 2:13
    understand the main models.
  • 2:13 - 2:16
    And the five basic skills for object-modeling
    are finding
  • 2:16 - 2:23
    objects, identifying collaborations, defining
    business rules, and assigning services
  • 2:23 - 2:26
    and attributes.
  • 2:26 - 2:27
    So I just want to make sure we're all
  • 2:27 - 2:30
    on the same page, in, in terms of what
  • 2:30 - 2:32
    a domain model is. So we're just gonna review
  • 2:32 - 2:35
    the scenario of shipping an order, which would
    behest
  • 2:35 - 2:38
    be an economist domain.
  • 2:38 - 2:42
    Now, a domain really represents a business
    process. So
  • 2:42 - 2:44
    let's go through, through this example. So
    we have
  • 2:44 - 2:47
    a business request that comes into our domain.
    In
  • 2:47 - 2:51
    this case it's to ship an order. An order
  • 2:51 - 2:55
    which represents a business object will receive
    this, and
  • 2:55 - 2:58
    it will go ahead and create a shipment. Another
  • 2:58 - 3:00
    business object that it'll collaborate with.
  • 3:00 - 3:03
    But we probably want to make sure that order's
  • 3:03 - 3:05
    been paid for before we ship that order. It
  • 3:05 - 3:08
    probably wouldn't make much sense, business
    sense, right. So
  • 3:08 - 3:10
    we have a business role that will check that
  • 3:10 - 3:13
    that order's actually been paid for.
  • 3:13 - 3:17
    So, essentially, a business domain, or a domain
    model,
  • 3:17 - 3:21
    is a set of business objects that represent
    these
  • 3:21 - 3:26
    real-world entities. There are collaborations,
    there are business rules,
  • 3:26 - 3:30
    and there are services that respond to business
    requests.
  • 3:30 - 3:33
    Now, a model is simply a representation of
    something.
  • 3:33 - 3:36
    It could be a mental model, our mental understanding
  • 3:36 - 3:39
    of how a business process works. It might
    be
  • 3:39 - 3:42
    a graphical notation or, sorry, a graphical
    model such
  • 3:42 - 3:45
    as a notation that I'm using up here. Or
  • 3:45 - 3:48
    it might even be codified in your models directory
  • 3:48 - 3:50
    in your Rails application.
  • 3:50 - 3:53
    Of course, there are other concerns when you're
    building
  • 3:53 - 3:56
    an application. These things like persisting
    those business objects
  • 3:56 - 4:02
    to a database, generating HTML or JSON, or
    even
  • 4:02 - 4:05
    handling that HTTP request that comes into
    your controller.
  • 4:05 - 4:08
    But these are things that are outside of your
  • 4:08 - 4:10
    domain model. And you can, can think of the
  • 4:10 - 4:16
    domain model as the heart of your application.
  • 4:16 - 4:18
    So I use this term business services when
    a
  • 4:18 - 4:21
    business request comes in, we'll use a business
    service
  • 4:21 - 4:24
    to respond to that request. Now, this is where
  • 4:24 - 4:27
    the services that you might have heard in
    the
  • 4:27 - 4:30
    previous talk on domain-driven design, and
    it's a pattern
  • 4:30 - 4:33
    that Rails developers have developed over
    the last couple
  • 4:33 - 4:36
    of years, where we create a service class
    to
  • 4:36 - 4:39
    encapsulate logic such as, sort of, sending
    out an
  • 4:39 - 4:44
    email or finding, finding a user record.
  • 4:44 - 4:46
    And the idea is to kind of thin down
  • 4:46 - 4:48
    the responsibilities of the controller. When
    I use the
  • 4:48 - 4:51
    term service, I'm not referring to that. I'm
    referring
  • 4:51 - 4:54
    to this idea of responding to a business request.
  • 4:54 - 4:56
    I'll try to use the, the term business service
  • 4:56 - 5:02
    to differentiate from this idea of a service
    class.
  • 5:02 - 5:06
    So why, why object modeling? Well, it feels
    like
  • 5:06 - 5:09
    there's a gap between user stories. You know,
    user
  • 5:09 - 5:12
    stories are great at requirements gathering.
    They're great for
  • 5:12 - 5:18
    describing business requests at, from the
    end user's perspective.
  • 5:18 - 5:20
    But how do we take those requirements and
    then
  • 5:20 - 5:23
    go ahead and implement that model in our Rails
  • 5:23 - 5:23
    application?
  • 5:23 - 5:27
    It's almost like we're missing a tool. We're
    missing
  • 5:27 - 5:31
    a tool to represent this underlying business
    model. A
  • 5:31 - 5:34
    tool to identify the business objects that
    represent these
  • 5:34 - 5:38
    real-world entities. A tool to define the
    define rules
  • 5:38 - 5:41
    that govern these collaborations.
  • 5:41 - 5:44
    I think as Rails developers, we kind of lack
  • 5:44 - 5:47
    a language, in terms of talking about domains.
    Normally,
  • 5:47 - 5:49
    we talk about domains in the form of associations
  • 5:49 - 5:54
    and has_many and belongs_to.
  • 5:54 - 5:56
    Object modeling is a practice, and these five
    basic
  • 5:56 - 5:59
    skills will help us bridge this gap between
    user
  • 5:59 - 6:02
    stories and implementation. Now, I just want
    to be
  • 6:02 - 6:05
    clear in terms of setting expectations for
    this talk.
  • 6:05 - 6:08
    I'm not gonna be showing any code. OK. Great.
  • 6:08 - 6:11
    No one got up and left. That's a good
  • 6:11 - 6:11
    sign.
  • 6:11 - 6:14
    And, so there's gonna be no code examples.
    And
  • 6:14 - 6:16
    there'll be lots of talks that are, over the
  • 6:16 - 6:19
    next couple of days, you know, showing different
    implementations.
  • 6:19 - 6:21
    And the thing is with this, with this practice
  • 6:21 - 6:25
    of object modeling, I believe it's independent
    of implementation.
  • 6:25 - 6:28
    It just helps you understand the business
    model itself.
  • 6:28 - 6:32
    Now, this idea of, this practice of object
    modeling,
  • 6:32 - 6:36
    it's not new. And Peter Coad first discussed
    this
  • 6:36 - 6:40
    in his book, Java Modeling in Color with UML.
  • 6:40 - 6:43
    This was first published in 1999. And, this
    is
  • 6:43 - 6:46
    not gonna be a popular book for Rubyists,
    right.
  • 6:46 - 6:47
    It has two things going wrong with it. It
  • 6:47 - 6:51
    has Java and UML in the title.
  • 6:51 - 6:53
    But there were some other books that were
    published
  • 6:53 - 6:55
    around the time, and other ones such as Streamlined
  • 6:55 - 6:58
    Object Modeling by Jill Nicola. And this really
    influenced
  • 6:58 - 7:02
    my thinking in terms of how to understand
    a
  • 7:02 - 7:04
    business domain.
  • 7:04 - 7:07
    And what I like about object modeling is that
  • 7:07 - 7:10
    it provides us a framework. Very much like
    Rails
  • 7:10 - 7:14
    provides us a framework in terms of providing
    us
  • 7:14 - 7:17
    guidance in terms of structuring our application.
    It provides
  • 7:17 - 7:22
    us conventions. And it helps us accelerate
    our web
  • 7:22 - 7:23
    development.
  • 7:23 - 7:25
    And object modeling's a little like that.
    It allows
  • 7:25 - 7:28
    us to discuss, visualize, and help us, guide
    us
  • 7:28 - 7:31
    in terms of implementing those domains. But
    it also,
  • 7:31 - 7:35
    it helps us to accelerate our understanding
    of those
  • 7:35 - 7:36
    business domains.
  • 7:36 - 7:40
    Now, I'm not advocating any big upfront design.
    This
  • 7:40 - 7:44
    is simply a tool to sketch out those ideas,
  • 7:44 - 7:47
    to collaborate with your team members and
    help guide
  • 7:47 - 7:51
    your implementation. Sure, the diagrams that
    I'm going to
  • 7:51 - 7:54
    be using today are URML, UML, the unified
    modeling
  • 7:54 - 7:59
    language. But these are simply communication
    tools. The goal
  • 7:59 - 8:02
    is not the diagrams themselves.
  • 8:02 - 8:07
    Now as object modelers, our basic building
    blocks are
  • 8:07 - 8:10
    objects. Which is fantastic, cause as Rubyists,
    we work
  • 8:10 - 8:13
    in a object-oriented language. Now, when I
    speak about
  • 8:13 - 8:16
    objects, I'm going to speak in the first person.
  • 8:16 - 8:20
    And this helps us personify these objects.
  • 8:20 - 8:27
    So objects have three responsibilities. Who
    I know, what
  • 8:27 - 8:32
    I do, and what I know.
  • 8:32 - 8:34
    An example of that, coming back to an order,
  • 8:34 - 8:36
    an order would know a number, it would know
  • 8:36 - 8:38
    its state - if it's paid. It would know
  • 8:38 - 8:41
    a timestamp for when it was purchased at.
    Of
  • 8:41 - 8:43
    course, it knows other collaborators. So it
    knows a
  • 8:43 - 8:46
    shipment and it knows how to ship itself:
    its
  • 8:46 - 8:49
    business service.
  • 8:49 - 8:51
    So now that we have this building block, let's
  • 8:51 - 8:56
    look at finding objects, our first skill.
  • 8:56 - 8:59
    The problem with finding objects is that often
    we
  • 8:59 - 9:02
    look at business objects as unique. They're
    these pretty
  • 9:02 - 9:05
    little snow flakes. But in effect, we can
    group
  • 9:05 - 9:09
    objects with more or less the same responsibilities
    of
  • 9:09 - 9:12
    what, who I know, what I do, and what
  • 9:12 - 9:14
    I know.
  • 9:14 - 9:16
    And these groups are known as archetypes,
    the term
  • 9:16 - 9:19
    that Peter Coad assigned to this. And we have
  • 9:19 - 9:23
    four archetypes. We have an event, a role,
    a
  • 9:23 - 9:27
    party, place, or thing, or a description.
    Party, place,
  • 9:27 - 9:29
    or thing's a little bit of a mouthful to
  • 9:29 - 9:31
    say every time, so we'll refer to these as
  • 9:31 - 9:34
    the PPTs.
  • 9:34 - 9:38
    So let's look at our first archetype. Our
    first
  • 9:38 - 9:41
    archetype are events. And these are modeled
    as transactions
  • 9:41 - 9:45
    within our domain. They're the most important
    business objects.
  • 9:45 - 9:47
    They're the glue for all the other objects
    in
  • 9:47 - 9:51
    our business domain. And without an event,
    I would
  • 9:51 - 9:56
    assert the application is simply a catalog
    application.
  • 9:56 - 9:58
    So we've got some examples up here. So in
  • 9:58 - 10:00
    the, in the domain of the ecommerce we would
  • 10:00 - 10:02
    have an order and a shipment. These are transactions
  • 10:02 - 10:06
    within that domain. If we're modeling a hotel
    reservation
  • 10:06 - 10:09
    system or a car reservation, we'd have a reservation
  • 10:09 - 10:12
    event.
  • 10:12 - 10:14
    And we have two types of events. We have
  • 10:14 - 10:17
    a point in time and an interval. So a
  • 10:17 - 10:19
    point in time has a single timestamp, such
    as
  • 10:19 - 10:23
    order, with the purchased_at date. And then
    we have
  • 10:23 - 10:29
    reservation. A reserv- sorry. We have an internal
    archetype,
  • 10:29 - 10:31
    illustrated by the reservation here.
  • 10:31 - 10:35
    And this is timestamped, or bookend by two
    timestamps.
  • 10:35 - 10:39
    So the checkin_at date and the checkout.
  • 10:39 - 10:42
    Now, roles don't live in isolation. They,
    they're the
  • 10:42 - 10:46
    glue in the domain. And other objects interact
    in
  • 10:46 - 10:50
    this event. And we use roles to represent
    the
  • 10:50 - 10:54
    way an object participates in this event.
    So as
  • 10:54 - 10:57
    an example, we have a customer and a sales
  • 10:57 - 10:59
    agent that would interact with an order. And
    a
  • 10:59 - 11:04
    fulfillment provider that would interact with
    the shipment.
  • 11:04 - 11:08
    So if we have roles, then we need actors.
  • 11:08 - 11:11
    And the actors in our domain, as, are these,
  • 11:11 - 11:15
    is the PPTs. Now, so, a party would be
  • 11:15 - 11:19
    a person or an organization. The place would
    be,
  • 11:19 - 11:22
    such of a thing as a warehouse if we
  • 11:22 - 11:24
    were doing shipment. And everything else is
    a thing.
  • 11:24 - 11:27
    So, again, an example here is the, is the
  • 11:27 - 11:28
    product.
  • 11:28 - 11:34
    And our final archetype is a description.
    And descriptions
  • 11:34 - 11:39
    are responsible for describing a collection
    of similar objects,
  • 11:39 - 11:41
    such as our PPTs. An example of this would
  • 11:41 - 11:45
    be a product category that would describe
    a, a
  • 11:45 - 11:47
    collection of products. A collection of things
    such as
  • 11:47 - 11:50
    t-shirts. Or a collection of jeans on an ecommerce
  • 11:50 - 11:51
    site.
  • 11:51 - 11:54
    Now, the concept of a description object can
    be
  • 11:54 - 11:57
    a little tough to kind of grasp sometimes.
    So
  • 11:57 - 11:58
    I'll talk about this in a little bit more
  • 11:58 - 12:03
    detail when we talk about identifying collaborations.
  • 12:03 - 12:09
    Now, when we're collaborating or presenting
    a diagram visually,
  • 12:09 - 12:10
    as soon as we have a few business objects
  • 12:10 - 12:13
    on a, on a diagram, it becomes a little
  • 12:13 - 12:16
    tough to navigate. Don't worry, you're not
    supposed to
  • 12:16 - 12:19
    be able to read all the details here. I'm
  • 12:19 - 12:21
    just gonna illustrate something.
  • 12:21 - 12:24
    But we can solve this issue in, in terms
  • 12:24 - 12:28
    of navigating these diagrams. We can add color,
    to
  • 12:28 - 12:34
    give another layer of information. Did anyone
    notice the
  • 12:34 - 12:36
    slides change color when I was talking about
    the
  • 12:36 - 12:41
    archetypes? Anyone paying notice? Oh, one
    person. What, what,
  • 12:41 - 12:42
    what color was event?
  • 12:42 - 12:42
    Sorry?
  • 12:42 - 12:43
    AUDIENCE: Yellow.
  • 12:43 - 12:47
    N.H.: Yellow? Almost. It was the role. But,
    the
  • 12:47 - 12:50
    event was the pink or the red. And pink's
  • 12:50 - 12:53
    a great color for an event, cause it highlights
  • 12:53 - 12:57
    sensitivity in the domain model. It's this
    hot spot.
  • 12:57 - 13:00
    We'll use yellow for roles. The green for
    the
  • 13:00 - 13:05
    PPTs. And the blue for the description.
  • 13:05 - 13:07
    So we can take a visualization of this in
  • 13:07 - 13:10
    terms of our domain model and add color to
  • 13:10 - 13:13
    that, and you can immediately see this hotspot
    within
  • 13:13 - 13:15
    your domain model.
  • 13:15 - 13:17
    You can see the events and you can see
  • 13:17 - 13:20
    the other objects interacting with those events
    through the
  • 13:20 - 13:21
    yellow roles.
  • 13:21 - 13:26
    Now, more importantly, we have this awesome
    collaboration tool
  • 13:26 - 13:30
    where we can use post-it notes that correspond
    to
  • 13:30 - 13:33
    these colored archetypes, and a white board,
    and with
  • 13:33 - 13:36
    our team members we can collaborate in an
    agile
  • 13:36 - 13:42
    manner into, on our business domain.
  • 13:42 - 13:45
    So now we have these four archetypes that
    helps
  • 13:45 - 13:49
    us guide finding business objects in our domain.
    But
  • 13:49 - 13:51
    you might have found, might have noticed that
    it
  • 13:51 - 13:53
    was a little difficult for me to talk about
  • 13:53 - 13:56
    one object in isolation. And this leads us
    to
  • 13:56 - 14:02
    our next skill, identifying collaborations.
  • 14:02 - 14:05
    Before moving onto collaborations, I just
    wanted to discuss
  • 14:05 - 14:10
    this idea of associations versus collaborations.
    As Rails developers,
  • 14:10 - 14:13
    we're very familiar with the idea of associations,
    from,
  • 14:13 - 14:17
    from ActiveRecord. But associations kind of
    have this idea
  • 14:17 - 14:21
    of a passive relationship, where collaborations
    kind of communicates
  • 14:21 - 14:25
    this idea of an active relationship with dialogue.
  • 14:25 - 14:28
    And dialogue becomes very important when we
    talk about
  • 14:28 - 14:30
    business rules. So I'm gonna use the idea
    of
  • 14:30 - 14:33
    collaborations for the rest of this talk.
  • 14:33 - 14:39
    Now, identifying collaborations addresses
    this object's responsibility of who
  • 14:39 - 14:44
    I know. Now, often we think about objects
    in
  • 14:44 - 14:48
    isolation. We think about a customer. We think
    about
  • 14:48 - 14:52
    an order. But the presence of one business
    object
  • 14:52 - 14:56
    suggests the presence of another.
  • 14:56 - 14:59
    And this is really highlighted by this, what
    I've
  • 14:59 - 15:03
    dubbed the elementary collaboration pattern.
    So let's walk through
  • 15:03 - 15:05
    this. So when we have the presence of an
  • 15:05 - 15:08
    event, we know that that, there's a role required
  • 15:08 - 15:11
    to interact with that event. And if we have
  • 15:11 - 15:14
    roles, we need an actor. And this is our
  • 15:14 - 15:16
    PPTs. And, of course, if we have a collection
  • 15:16 - 15:20
    of PPTs, perhaps we need a description to
    describe
  • 15:20 - 15:22
    that collection.
  • 15:22 - 15:26
    Now, this is essentially a template. And templates
    are
  • 15:26 - 15:30
    meant to be modified based on need. An example
  • 15:30 - 15:33
    of this, if you have a PPT that only
  • 15:33 - 15:37
    participates in one event, do not create a
    dedicated
  • 15:37 - 15:40
    role for that. That's just going to complicate
    your
  • 15:40 - 15:43
    object model.
  • 15:43 - 15:46
    Here we have an example of a person interacting
  • 15:46 - 15:50
    with order. So a person can either interact
    with
  • 15:50 - 15:53
    that as a customer or as a sales agent.
  • 15:53 - 15:56
    So, of course, the customer is the one who
  • 15:56 - 15:58
    is purchasing that order, and the other is
    the,
  • 15:58 - 16:00
    perhaps, approving that order.
  • 16:00 - 16:03
    Now, we might have a business role that suggests
  • 16:03 - 16:06
    that we, the same person cannot be the same,
  • 16:06 - 16:09
    sorry, the same person cannot play the roles
    at
  • 16:09 - 16:12
    the same time. Meaning they can't be the customer
  • 16:12 - 16:14
    and the sales agent.
  • 16:14 - 16:18
    There's another notation that I've introduced
    here, in terms
  • 16:18 - 16:21
    of the UML, is that we have multiplicity rules
  • 16:21 - 16:24
    identified. So the one next to the customer
    on
  • 16:24 - 16:28
    the right-hand side suggests that there's
    a, an order
  • 16:28 - 16:31
    only belongs to one customer. And a customer
    can
  • 16:31 - 16:33
    actually belong to many orders, and that's
    denoted by
  • 16:33 - 16:37
    the zero and the asterisks next to the order.
  • 16:37 - 16:43
    Now, here's a description of the PPTs, sorry,
    a
  • 16:43 - 16:46
    PPT versus a description. I was talking about
    how
  • 16:46 - 16:48
    descriptions might be a little bit tough to
    grasp.
  • 16:48 - 16:50
    We're just gonna go through an example here.
  • 16:50 - 16:55
    Here, we have a vehicle that's uniquely identified
    by
  • 16:55 - 16:58
    a registration number. And we have a vehicle
    make
  • 16:58 - 17:02
    that describes that vehicle. It describes
    the model and
  • 17:02 - 17:05
    it describes the year that model was released.
  • 17:05 - 17:07
    Let's take a little concrete example and we'll
    make
  • 17:07 - 17:10
    this a little clearer. So here we have four
  • 17:10 - 17:15
    instances of, of a vehicle. We have one and
  • 17:15 - 17:18
    two, and you'll see that there's a uniquely
    identified
  • 17:18 - 17:22
    registration number. But we have duplicated
    data here, sorry,
  • 17:22 - 17:25
    duplicated attributes here, with the model
    and year.
  • 17:25 - 17:28
    And this is repeated again in the instances
    three
  • 17:28 - 17:31
    and four. I've highlighted it here so you
    can
  • 17:31 - 17:35
    see the, the repeating data.
  • 17:35 - 17:37
    And we can, of course, extract them. We'll
    use
  • 17:37 - 17:40
    a business, business, request kind of term
    business service
  • 17:40 - 17:43
    when we can extract those repeating attributes.
  • 17:43 - 17:44
    (weird audio - (00:17:45)
  • 17:44 - 17:48
    And here business object in the, with the
    registration
  • 17:48 - 17:51
    number is our vehicle, and with the model
    and
  • 17:51 - 17:54
    year we have the vehicle make. So the instances
  • 17:54 - 17:56
    of one and two of the vehicle are described
  • 17:56 - 17:58
    by the first instance of the description,
    which is
  • 17:58 - 18:03
    the Corolla 2010. And the rows three, sorry,
    the
  • 18:03 - 18:05
    instances three and four are described by
    the second
  • 18:05 - 18:10
    instance of that description, the Focus 2014.
  • 18:10 - 18:12
    So you can sort of think about this in
  • 18:12 - 18:17
    the terms of data normalization.
  • 18:17 - 18:22
    Now, archetypes can collaborate with the same
    archetype. So
  • 18:22 - 18:26
    a PPT can collaborate with another PPT. In
    this
  • 18:26 - 18:29
    instance we're gonna look at event collaborations.
    And there's
  • 18:29 - 18:31
    two event collaborations that we'll have a
    look at.
  • 18:31 - 18:34
    The first one is the composite. The composite
    is
  • 18:34 - 18:38
    actually made up of other events.
  • 18:38 - 18:40
    So here we have the, the composite transaction
    and
  • 18:40 - 18:44
    the line item. The example is the order and
  • 18:44 - 18:46
    the order line item. I've introduced another
    little bit
  • 18:46 - 18:50
    of UML notation with that solid, the solid
    diamond,
  • 18:50 - 18:55
    and that denotes the composite within this
    pattern.
  • 18:55 - 18:59
    Another event collaboration pattern is the
    follow-up pattern, where
  • 18:59 - 19:00
    we have a transaction and then we have a
  • 19:00 - 19:03
    follow-up transaction. And in this case we
    have an
  • 19:03 - 19:07
    order that is followed up by a shipment. Another
  • 19:07 - 19:09
    example of this would be an order followed
    up
  • 19:09 - 19:12
    by a payment.
  • 19:12 - 19:14
    So let's sort of take a look at this
  • 19:14 - 19:17
    in a, in an example, a larger example. Here
  • 19:17 - 19:20
    we have a, a product description describing
    a collection
  • 19:20 - 19:24
    of products. This product is interacting with
    this order
  • 19:24 - 19:27
    line item. And this is kind of a, this,
  • 19:27 - 19:29
    this product interacting with a, a order line
    item,
  • 19:29 - 19:32
    the idea of the thing interacting with a,
    with
  • 19:32 - 19:34
    a line item. That's a common pattern that
    you'll
  • 19:34 - 19:38
    see in, in domains.
  • 19:38 - 19:39
    But the interesting thing here is the, is
    the
  • 19:39 - 19:43
    composite. And that, the highlighting's not
    showing up very
  • 19:43 - 19:45
    well. I apologize for that.
  • 19:45 - 19:47
    But the order and the order line item is
  • 19:47 - 19:51
    our composite pattern that we've seen before.
    The interesting
  • 19:51 - 19:54
    thing is, we repeat this pattern as well.
    So
  • 19:54 - 19:57
    with a shipment and a shipment line item,
    there
  • 19:57 - 20:00
    is a comp, a composite.
  • 20:00 - 20:02
    And we can repeat this again in terms of
  • 20:02 - 20:04
    the order line, sorry, the shipment line item
    is
  • 20:04 - 20:09
    a follow-up for the order-line item. But this
    is
  • 20:09 - 20:11
    when the magic starts to happen, is when we
  • 20:11 - 20:14
    had another composite with a return and return
    line-item.
  • 20:14 - 20:19
    And again, and this is a collaboration, a
    composite
  • 20:19 - 20:20
    collaboration.
  • 20:20 - 20:23
    And we can use these, these collaboration
    patterns as
  • 20:23 - 20:28
    a building block in our domains as well.
  • 20:28 - 20:32
    And this moves us on to business rules. So,
  • 20:32 - 20:34
    you know, so we're talking about these collaborations,
    but
  • 20:34 - 20:40
    what governs these collaborations. So business
    rules are either
  • 20:40 - 20:45
    policies that specify how a business should
    operate, or
  • 20:45 - 20:49
    these are constraints that are forced upon
    a business,
  • 20:49 - 20:52
    such as laws determined by a government.
  • 20:52 - 20:54
    Now often when we think about business rules,
    we
  • 20:54 - 20:58
    kind of think about validation roles, where
    we're just
  • 20:58 - 21:01
    validation that an email is present, or if
    it's
  • 21:01 - 21:04
    in the correct format such as using a regular
  • 21:04 - 21:09
    expression for that email address. But business
    rules extend
  • 21:09 - 21:10
    beyond this.
  • 21:10 - 21:13
    They govern, or validate, collaborations.
  • 21:13 - 21:20
    Now, if business rules govern collaborations,
    then each partner,
  • 21:20 - 21:23
    that business object, must determine if that
    collaboration is
  • 21:23 - 21:27
    valid. Because each partner may have a different
    condition
  • 21:27 - 21:31
    to determine if that is a valid collaboration.
  • 21:31 - 21:35
    Here we have an example of a shipment and
  • 21:35 - 21:38
    a shipping method that are looking to collaborate.
    The
  • 21:38 - 21:40
    shipment has a total weight, and it might
    be
  • 21:40 - 21:43
    expedited. So we want to get that shipment
    out
  • 21:43 - 21:43
    quickly.
  • 21:43 - 21:46
    A shipping method has a, has a maximum weight
  • 21:46 - 21:49
    and a duration. So let's look at these two
  • 21:49 - 21:52
    ob, business objects collaborating.
  • 21:52 - 21:56
    Now, a shipping method adds a constraint on
    its
  • 21:56 - 22:00
    collaboration with a shipment. It will not
    collaborate with
  • 22:00 - 22:05
    a shipment whose total weight exceeds the
    maximum weight.
  • 22:05 - 22:10
    Likewise, a shipment has a constraint on its
    collaboration
  • 22:10 - 22:14
    with the shipping method. It will not collaborate,
    sorry,
  • 22:14 - 22:18
    if that shipment is expedited, it will not
    collaborate
  • 22:18 - 22:21
    with a shipment, sorry, with a shipping method
    whose
  • 22:21 - 22:24
    duration exceeds two days.
  • 22:24 - 22:29
    So from this example, we've illustrated that
    each partner
  • 22:29 - 22:33
    must validate the collaboration. And each
    partner adds a
  • 22:33 - 22:38
    constraint, sorry, each partner adds a constraint
    to that
  • 22:38 - 22:41
    collaboration, owns that business rule. And
    that business rule's
  • 22:41 - 22:46
    encapsulated in that business object. And
    it shields that
  • 22:46 - 22:50
    condition from its collaborator.
  • 22:50 - 22:53
    So now that we understand that business rules
    are
  • 22:53 - 22:57
    simply not validation rules, that they govern
    these collaborations,
  • 22:57 - 23:00
    when do these collaborations form?
  • 23:00 - 23:03
    And this takes us to our fourth skill or
  • 23:03 - 23:06
    assigning services.
  • 23:06 - 23:10
    And services, it's, are related to the responsibility
    of
  • 23:10 - 23:16
    what I do. Now, business services respond
    to business
  • 23:16 - 23:21
    requests. They form new collaborations. They
    dissolve collaborations. And
  • 23:21 - 23:25
    they may even create new event objects. Of
    course,
  • 23:25 - 23:27
    services can update attributes.
  • 23:27 - 23:31
    However, for this talk, I'm gonna focus on
    collaboration.
  • 23:31 - 23:34
    Now, as a reminder, we'll just revisit this
    scenario
  • 23:34 - 23:37
    from the beginning of my talk. Here, we have
  • 23:37 - 23:40
    a business request coming into our domain,
    and that's
  • 23:40 - 23:43
    gonna be to ship an order. The order's going
  • 23:43 - 23:45
    to respond to that. But it's gonna check that
  • 23:45 - 23:47
    business rule to make sure it's being paid.
    And
  • 23:47 - 23:50
    then it'll go ahead and it will create a
  • 23:50 - 23:55
    new shipment and collaborate with that.
  • 23:55 - 23:57
    So a challenge when we're object modeling
    is that
  • 23:57 - 24:02
    in the real world, entities are acted upon.
    Someone
  • 24:02 - 24:06
    ships an order. But when we're object modeling,
    objects
  • 24:06 - 24:10
    that represent those real world entities perform
    the actions
  • 24:10 - 24:12
    themselves.
  • 24:12 - 24:15
    So an order will ship itself. And the reason
  • 24:15 - 24:18
    for that is that all the information inside
    an
  • 24:18 - 24:22
    object, sorry, all the information needed
    to act on
  • 24:22 - 24:25
    that object is inside of that object. So let
  • 24:25 - 24:27
    that object do the work.
  • 24:27 - 24:30
    Otherwise we end up sort of creating these
    dedicated
  • 24:30 - 24:34
    coordinating objects like shipment manager.
    And an object like
  • 24:34 - 24:38
    shipment manager doesn't represent a real-world
    entity and just
  • 24:38 - 24:44
    adds conceptual noise to our domain model.
  • 24:44 - 24:47
    So with this in mind, we assign this ship
  • 24:47 - 24:50
    service to the order, so it can respond to
  • 24:50 - 24:55
    that business request. And the service becomes
    an object
  • 24:55 - 24:58
    factory for the shipment. And this is a pat,
  • 24:58 - 25:02
    and follows the pattern of services becoming
    object factories
  • 25:02 - 25:06
    for events.
  • 25:06 - 25:08
    And here we come to our last skill, in
  • 25:08 - 25:11
    terms of assigning attributes. And we've already
    taken a
  • 25:11 - 25:16
    look at some attributes. These attributes
    respond to what
  • 25:16 - 25:18
    I know.
  • 25:18 - 25:20
    So coming back to our vehicle and our vehicle
  • 25:20 - 25:25
    make, a vehicle with its registration number
    is a
  • 25:25 - 25:29
    descriptive or tacking attribute, which is
    typical of a
  • 25:29 - 25:32
    PPT. With the vehicle make we have these two
  • 25:32 - 25:37
    descriptive attributes of a, of the model
    and the
  • 25:37 - 25:39
    year.
  • 25:39 - 25:41
    From our order example, again, we, for the
    order
  • 25:41 - 25:44
    it has this tracking attribute of a number.
    It
  • 25:44 - 25:47
    knows its state and it has this time stamp
  • 25:47 - 25:51
    that's, that point in time events have.
  • 25:51 - 25:56
    Now, Jill Nicola, in her book Streamlined
    Object Modeling,
  • 25:56 - 26:00
    has identified six types of attributes. I
    won't go
  • 26:00 - 26:02
    through all six, but you can see some examples
  • 26:02 - 26:04
    on the right hand side there.
  • 26:04 - 26:07
    I'll focus on two attributes. The life cycle
    state
  • 26:07 - 26:11
    and the operating state. The life cycle state
    is
  • 26:11 - 26:16
    a, is a one-way state transition. So an order
  • 26:16 - 26:20
    would transition from pending to paid to complete,
    but
  • 26:20 - 26:23
    it won't revert back to that stage.
  • 26:23 - 26:27
    An operating stage is a state that switches
    back
  • 26:27 - 26:30
    and forth between two states. So an example
    here
  • 26:30 - 26:32
    is a product could be active, so active in
  • 26:32 - 26:35
    a, in a catalog. We could switch that off
  • 26:35 - 26:39
    and it wouldn't appear, appear in the catalog
    anymore.
  • 26:39 - 26:40
    And then we could switch it on. So it
  • 26:40 - 26:45
    switches back and forth.
  • 26:45 - 26:48
    So now that you've been introduced to the
    five
  • 26:48 - 26:52
    basic skills of object modeling, we have a
    set
  • 26:52 - 26:55
    of skills to bridge this gap between your
    user
  • 26:55 - 27:00
    stories and your Rails application. You have
    a framework
  • 27:00 - 27:03
    to explore business domains.
  • 27:03 - 27:07
    So, I've simply given you an introduction
    here. And
  • 27:07 - 27:10
    if this talk has resonated with you, you're
    probably
  • 27:10 - 27:14
    hungry for more. So I've outlined these three
    steps
  • 27:14 - 27:16
    to help get you started.
  • 27:16 - 27:20
    First, I've created a dedicated blog post
    providing some
  • 27:20 - 27:24
    online resources that, resources that you
    can read today.
  • 27:24 - 27:26
    Plus links to the books that I talked about
  • 27:26 - 27:28
    in this talk.
  • 27:28 - 27:33
    Secondly, talk, share this with you team members.
    This
  • 27:33 - 27:36
    idea of object modeling is awesome to use
    as
  • 27:36 - 27:38
    an individual, but the real power is when
    you
  • 27:38 - 27:41
    have this common language with your team mates,
    and
  • 27:41 - 27:44
    collaborate with each other.
  • 27:44 - 27:46
    And then the third step is buy some post-it
  • 27:46 - 27:50
    notes. Post-it notes are an awesome collaboration
    tool and
  • 27:50 - 27:53
    some, and a simple collaboration tool, and
    it makes
  • 27:53 - 27:57
    this whole modeling fun.
  • 27:57 - 28:00
    So the next time, when a team member asks
  • 28:00 - 28:04
    you, how do I model this? Use archetypes to
  • 28:04 - 28:10
    guide you in finding objects. Use color to
    visualize
  • 28:10 - 28:13
    and collaborate with your team members. Use
    the presence
  • 28:13 - 28:17
    of one object to suggest the presence of another
  • 28:17 - 28:22
    and form collaborations. Use business rules
    to validate or
  • 28:22 - 28:27
    govern these collaborations. Assign services
    to business objects to
  • 28:27 - 28:32
    fulfill business requests. And use these skills
    to build
  • 28:32 - 28:36
    a model that mirrors the business, enabling
    you to
  • 28:36 - 28:40
    correctly and efficiently understand the domain.
  • 28:40 - 28:42
    Thank you.
Title:
RailsConf 2014 - Modeling on the Right Side of the Brain by Nicholas Henry
Description:

more » « less
Duration:
29:11

English subtitles

Revisions