Re: How should a container class "know" its contained objects?



On Jan 16, 6:47 pm, "Daniel T." <danie...@xxxxxxxxxxxxx> wrote:
Veloz <michaelve...@xxxxxxxxx> wrote:
I've done some more digging and found a couple other nuggets out
there, mostly from Martin.

Here's one:

"We [should] create objects of the things that have behavior, not the
things that carry data.."

This makes sense to me on a bunch of different angles.

But, then, where does that leave the modeling of the data? Does the
data not deserve some representation in our application?

The obvious answer is "yes", that data needs to be modeled in some
way.

Joe has a robot with type A arms, a robot with type B arms, and a robot
with type C arms.

Mary has a robot that can do job X, a robot that can do job Y, and a
robot that can do job Z.

Now, if Joe wants to sell you a robot, you have to ask him, "but what
jobs are these robots good for?" Whereas if Mary tries to sell you a
robot, you don't really worry about what kind of arms they have...

The data is less important than what job the class does.

Agreed overall.

Let's say one of the functions Mary's robots know how to do is to
perform some custom analysis on something known as a ZippyBook. The
ZippyBook is a domain concept that somewhat mimics a real book. It can
contain chapters, an index and so on. Now, it's pretty easy to
conclude from past conversations that the most interesting/useful
modeling will revolve around the custom analysis, because that's where
the most interesting/important behaviors are.

But what about modeling the ZippyBook? Mary's Robot needs to get
content for ZippyBooks through a UI it must create. As it does this,
it needs to enforce certain business rules about how many chapters
there must be, what kind of duplicate information is allowed, certain
requirements related to the items in the table of contents, validation
of hyperlinks, etc.

For the sake of discussion, let's say the UI is smart enough to
understand what can go into a ZippyBook, and to enforce (ignoring what
the UI should/shouldn't know regarding business rules).

But then how are you going to store the ZippyBook in your software so
that you know which chapters, table of contents, etc, go with which
ZippyBook, ? That is, at some point the user of the Robot is going to
want to see ZippyBooks in an expected format... and the software must
know how to correctly "assemble one"

And furthermore, let's say we have some code that needs to create
ZippyBooks dynamically.. Who is going to validate that the ZippyBook
rules are followed when creating it or populating it?

And lastly, let's say some other processes need to access parts of a
ZippyBook.. should these parts (chapters, table of contents) just be
global variables??

It seems to me that you need an entity class known as ZippyBook which
can house chapters, tables of contents, hyperlinks, whatever. And this
class, having the knowledge of its own data, would also enforce the
business rules as someone adds items to it, such as more chapters
etc. And as other code needs items (say a chapter from a ZIppyBook)
it should access the chapter through the ZippyBook.

Based on this I would say that we would end up with "entity" classes
in our design, which have behavior of the own (related to enforcing
rules, storing the data in a representationally useful way, etc) and
we would end up with objects that are more focused on algorithms and
other behaviors.

Yes???? :-)
M









So how am I to represent this data, enforce validation and
relationship rules for it, etc, except by creating classes to do so?

Unfortunately, I don't know enough about your system to say...

.



Relevant Pages

  • Re: How should a container class "know" its contained objects?
    ... Joe has a robot with type A arms, a robot with type B arms, and a ... Now, if Joe wants to sell you a robot, you have to ask him, "but ... The ZippyBook is a domain concept that somewhat mimics a real book. ...
    (comp.object)
  • Re: OT Buck Rogers aliens [was Errand of Mercy - Thoughts]
    ... So all the arms were really for was from going straight ... Why would humans design a robot that was so annoying? ... that they should not be ruled by the computers anymore, ... And Twikki became comic relief, ...
    (rec.arts.startrek.tech)
  • Making Robots
    ... the neural network that you are a part of. ... Now when you make a robot, and you use a computer, you are not giving it, ... but their body and arms and head would all ... So now you have a whole lot of people, making complex behaviors, in a 3d ...
    (sci.physics)
  • Re: 6 Ss of Capable Home Robots
    ... Arms aren't the issue. ... it really needs to learn that it shouldn't eat the sock on the floor. ... I have a list of 90 things that a robot could do and most of these ...
    (comp.robotics.misc)

Loading