Have I structured my Contexts correctly?

114 views
Skip to first unread message

Chris Richards

unread,
Apr 16, 2012, 12:43:57 PM4/16/12
to object-co...@googlegroups.com

Hello All


I have several contexts that allow an item in a nested set to be moved to any other point within the nested set. Each element in the tree has a parent, and children of a parent are ordered.

Currently I have 3 contexts that allow items to be moved to any other point in the tree :


class MoveAfterItem < Context

def new(source_item, target_item)

def execute


class MoveBeforeItem < Context

def new(source_item, target_item)

def execute


class MoveWithinItem < Context

def new(source_item, target_item)

def execute


Although this works fine I feel as though I haven't structured my Contexts using the use cases of the application.

I think the use case is "Be able to move items around the tree".


Based on this I think I should create a new single context that replaces the 3 other ones. This new context has 3 entry points :


class MoveItemAroundTree < Context

def new(source_item, target_item)

def move_after_item

def move_before_item

def move_within_item


Being able to move items around the tree is a major part of the functionality of this app. The application is a simple note taking application, where notes are arranged in a tree structure, any number of levels deep.


What are your thoughts on the new Context I have created? Any help is appreciated.


Regards

Chris


rune funch

unread,
Apr 16, 2012, 1:33:01 PM4/16/12
to object-co...@googlegroups.com
How's move before different from move after except that the roleplayers are swapped?


--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To view this discussion on the web visit https://groups.google.com/d/msg/object-composition/-/jRF8nw9s928J.
To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.

rune funch

unread,
Apr 16, 2012, 1:34:12 PM4/16/12
to object-co...@googlegroups.com
Can move within be expressed In terms of move before and after on a different tree level?



Den 16/04/2012 kl. 18.43 skrev Chris Richards <evilg...@gmail.com>:

Chris Richards

unread,
Apr 16, 2012, 2:12:06 PM4/16/12
to object-co...@googlegroups.com


>  How's move before different from move after except that the roleplayers are swapped?

Sorry, I don't think I was clear in my description.

Move before means to move a source item Before another specific item in the ordered list, and Move after means to move after a specific an item in the list.   

I have attached a screenshot of the "Tree" widget in my application.  In the screenshot, I have just clicked on a Move icon next to the "Child 3" item, which caused all of the "Before", "After" and "Within" buttons to appear next to all the other items in the tree.  Clicking on one of the buttons completes the action.


>  Can move within be expressed In terms of move before and after on a different tree level?

Possibly, but this wouldn't work when there are no existing items at a certain level. Also I think moving "After", "Before" and "Within" captures the fundamental action that is being performed and fits the users mental model quite well.

Thanks
Chris
To post to this group, send email to object-composition@googlegroups.com.
To unsubscribe from this group, send email to object-composition+unsub...@googlegroups.com.

Mikey B

unread,
Apr 17, 2012, 5:23:34 AM4/17/12
to object-co...@googlegroups.com

Hi chris,

Did you say you have working code for this or just at design stage? As im curious to see the code you have?

From what i read from your posts, your talking about represtational state and interactions, rather than system operations.

I think you should consider the Context for this inside the users mind. This can not be coded into your software as an object.

The users is performing the steps and not the software.

Mike brown.

To view this discussion on the web visit https://groups.google.com/d/msg/object-composition/-/5TrwtYSyio8J.
To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.

Chris Richards

unread,
Apr 17, 2012, 9:33:35 AM4/17/12
to object-co...@googlegroups.com
Mike

So what should my Context be called then?

If this is my Use Case : "User should be able to move items around the tree.  Tree organisation", then what is wrong with having a Context named MoveItemsAroundTree, and having multiple entry points for each type of movement? 

Chris
To unsubscribe from this group, send email to object-composition+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.

Chris Richards

unread,
Apr 17, 2012, 12:01:03 PM4/17/12
to object-co...@googlegroups.com

> Did you say you have working code for this or just at design stage? As I'm curious to see the code you have?

Here is the current Ruby code for this context, although it has been changing a lot :

https://gist.github.com/2407071

I know there is too much going on in the Data class.  For example, I am using the "resort" and "has_ancestry" libraries, which at  the moment need to be added to the data model.  I know this is wrong and I need to only import these libraries when they are used, in the role methods.

Thanks
Chris

Arjan Molenaar

unread,
Apr 17, 2012, 4:49:43 PM4/17/12
to object-co...@googlegroups.com

Hi,

What you implemented looks like a command pattern. That's perfectly fine for the operations you mean to perform. You're performing direct manupilation of the data. There is no real interaction taking place between the subjected nodes.

DCI is not a silver bullet. For 1:1 manupilation of data classes you're better of with a straight forward command pattern (there is no use case specific behaviour involved, no roles).

Just my 2ct.

Regards,

Arjan

Op 17 apr. 2012 18:01 schreef "Chris Richards" <evilg...@gmail.com> het volgende:
To view this discussion on the web visit https://groups.google.com/d/msg/object-composition/-/8J9ebP_lz8cJ.
To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.
Message has been deleted

Chris Richards

unread,
Apr 18, 2012, 3:18:28 AM4/18/12
to object-co...@googlegroups.com
At the moment it is only basic manipulation of the data , but the complexity of the interactions will increase when I add extra features to my application, such as versioning, collaboration, sharing and an audit trail.   So in the specific code you have seen, actions such as sending emails to users, and recording an audit trail will be added.   

Might the benefits of DCI be more obvious when these extra features are added?  This context will be the go-to place to look at all the interactions for moving an area.

Thanks
Chris

rune funch

unread,
Apr 18, 2012, 3:47:55 AM4/18/12
to object-co...@googlegroups.com
I'd still postulate that the users mental model (those that have not been tainted with the current implementation) only have one operation. Move. When did you in the real world first select and object to be moved and the select whether it should be placed before or after another object? In the real world we pick the object and move it to where we want it to be. This can be achieve in software as well and is one of the reasons why grad'n drop is so intuitive. We do as we would have done with real world objects. The interaction between the list of objects and the object being moved could be modelled as a simple interaction. That the current implementation deviates from the users mental model forcing them to consider concepts they wouldn't otherwise have considered does really affect the model of moving an object. The before, after and within is concepts from the developers model of the system and how the move-an-object is implemented it has nothing to do with the users goal of moving an object to a specific location.

-Rune


To unsubscribe from this group, send email to object-composition+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.

--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To view this discussion on the web visit https://groups.google.com/d/msg/object-composition/-/8J9ebP_lz8cJ.
To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.

--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To view this discussion on the web visit https://groups.google.com/d/msg/object-composition/-/-UlQHf7NEzQJ.
To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.

Chris Richards

unread,
Apr 18, 2012, 6:05:59 AM4/18/12
to object-co...@googlegroups.com
Rune,


> When did you in the real world first select and object to be moved and the select whether it should be placed before or after another object?

How can a decision to move something not include a description of the position relative to another object that it should be moved to?  e.g. "Move on top X", "Move inside X ", "Move in front of X",  "Move below X", "Move before X".  It is rare that in the real world you will hear someone say "Move" without then saying what object it should be moved relative to and the relative position to that object that it should be moved.  I don't see the problem.    The only alternative I think is to give an absolute position of where you want the object to be moved to, e.g. Move item x to position 3 in the list, but this definitely wouldn't fit the users mental model, especially in long lists.

I think it would be hard to describe where you want an item to be moved in a list without using the words "before" or "after", or similar words.  I think "Move Before" and "Move After" fits perfectly with the users mental model. 

I think you might be right about "Move Inside" though. 

> This can be achieve in software as well and is one of the reasons why drag'n drop is so intuitive.

Drag and drop generally only works when the number of lists is very small.  For more complex cases it breaks down and turns out to be more difficult and clumsy (Having to scroll down the page while dragging an item is always nasty.  Make sure you don't accidentally drop the item too!)  For example, when you are moving a folder on a file system, a user might drag and drop it if the folder being moved to is close-by.  If the target folder is a lot further down the file listing,  and will require some scrolling by the user or more work, then Cut and Paste is the method that is usually chosen.      The system I've chosen is actually surprisingly effective.

I initially used drag and drop but found it clumsy for my application.  Even when I used Drag and Drop, "Move Before", "Move After" and "Move Within" are still the operations being performed.

Chris
To view this discussion on the web visit https://groups.google.com/d/msg/object-composition/-/8J9ebP_lz8cJ.
To post to this group, send email to object-composition@googlegroups.com.
To unsubscribe from this group, send email to object-composition+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.

--
You received this message because you are subscribed to the Google Groups "object-composition" group.

rune funch

unread,
Apr 18, 2012, 6:41:11 AM4/18/12
to object-co...@googlegroups.com
Den 18/04/2012 kl. 12.06 skrev Chris Richards <evilg...@gmail.com>:

> How can a decision to move something not include a description of the position relative to another object that it should be moved to?

Pete: "James would you please move your chair over there" (Pete points
to the exact location between Laura and Kent)" it's not before Kent or
after Laura. It's relative to there position and it's "right there".
Human languages are a lot richer than programming language even though
in this case also vague (pointing is non-verbal). The users mental
model is not based on what can or what needs to be expressed when
coding a solution. Drag and drop feels natural because you tell the
computer to move stuff to "right there" you point with a mouse instead
of a finger. Describing the exact position is only needed when
straying from this real world solution.

Of course Pete could also say "James please move your chair" "Laura I
want James chair before yours" which is equivalent to first selecting
the object to be moved and then selecting the object it should be
placed before. Does that sound natural?

rune funch

unread,
Apr 18, 2012, 1:07:58 PM4/18/12
to object-co...@googlegroups.com
Den 18/04/2012 kl. 12.06 skrev Chris Richards <evilg...@gmail.com>:

> I initially used drag and drop but found it clumsy for my application. Even when I used Drag and Drop, "Move Before", "Move After" and "Move Within" are still the operations being performed.

My point is not that I think drag n drop is the perfect solution. As
I've understood your system the user does the following:
Selects an element to move
Click move before/after/within on a separate element

I don't think a regular user would think that way at least not without
having used the application for at while. That's not saying the
implementation is not working simply that I believe the operation the
user wish to perform is "move this element right there" the
interaction represents the operation the user wishes to perform.

Sometimes in software we invent entirely new ways of doing things that
our users have been doing for years but more commonly we support users
in doing what they have been doing for years. We create system that
fits into existing work flows. It's a lot easier to get users to
accept new systems if they simply make their every day life simpler.
At times there might be a benefit in challenging the users model of
how they should perform their work. The point I was trying to make is
that I think moving an element from A to B is in the first category.
Support the operation the user wish to perform and if at all possible
don't ask the users to concern them self with how it's implemented

Igor Tur

unread,
May 2, 2012, 10:33:40 AM5/2/12
to object-composition

Take any IDE - when you move a file in solution tree. It starts as UI
Command, for sure. But it also defined as a Use Case some where and it
may be long one.

Use Case: Move file from one project to another
Use Case: Move file inside of setup actions to control sequence of
actions

In any case, you use your mouse and start dragging a file => you start
your command
You move a mouse with a file => your are still in the command context
And now you "Drop that file" => your are again in the command context,
OnDrop() action. You didn't really move file yet, but now is a time to
select and start some Use Case where context is (file, source, drop
target)
You may use pretty generic Use Case "Move File" which does some basic
verification and call more specific Use Case.

So back to Chris' original question, I think that his 2nd sample, with
generic Use Case "MoveItemAroundTree" is appropriate if he has single
place where either one of original Use Cases should start.

class MoveItemAroundTree < Context
def new(source_item, target_item)
def move_after_item
def move_before_item
def move_within_item

If you have 3 buttons (or 3 mice :) ) and each is designated for very
specific action, then you don't need to create generic
"MoveItemAroundTree" - no one would call it; even if such Use Case
exist in project specs.

Igor

On Apr 17, 1:49 pm, Arjan Molenaar <gap...@gmail.com> wrote:
> Hi,
>
> What you implemented looks like a command pattern. That's perfectly fine
> for the operations you mean to perform. You're performing direct
> manupilation of the data. There is no real interaction taking place between
> the subjected nodes.
>
> DCI is not a silver bullet. For 1:1 manupilation of data classes you're
> better of with a straight forward command pattern (there is no use case
> specific behaviour involved, no roles).
>
> Just my 2ct.
>
> Regards,
>
> Arjan
> Op 17 apr. 2012 18:01 schreef "Chris Richards" <evilgeen...@gmail.com> het
> >>> On Apr 16, 2012 7:12 PM, "Chris Richards" <evilgeen...@gmail.com> wrote:
>
> >>>> <https://lh5.googleusercontent.com/-jxDRpGJULvc/T4xfuV_XeBI/AAAAAAAAAZ...>
>
> >>>> >  How's move before different from move after except that the
> >>>> roleplayers are swapped?
>
> >>>> Sorry, I don't think I was clear in my description.
>
> >>>> Move before means to move a source item Before another specific item in
> >>>> the ordered list, and Move after means to move after a specific an item in
> >>>> the list.
>
> >>>> I have attached a screenshot of the "Tree" widget in my application.
> >>>> In the screenshot, I have just clicked on a Move icon next to the "Child 3"
> >>>> item, which caused all of the "Before", "After" and "Within" buttons to
> >>>> appear next to all the other items in the tree.  Clicking on one of the
> >>>> buttons completes the action.
>
> >>>> >  Can move within be expressed In terms of move before and after on a
> >>>> different tree level?
>
> >>>> Possibly, but this wouldn't work when there are no existing items at a
> >>>> certain level. Also I think moving "After", "Before" and "Within" captures
> >>>> the fundamental action that is being performed and fits the users mental
> >>>> model quite well.
>
> >>>> Thanks
> >>>> Chris
>
> >>>> On Monday, April 16, 2012 6:34:12 PM UTC+1, Rune wrote:
>
> >>>>> Can move within be expressed In terms of move before and after on a
> >>>>> different tree level?
>
> >>>>> To view this discussion on the web visithttps://groups.google.com/d/*
> >>>>> *ms**g/object-composition/-/**jRF8nw9**s928J<https://groups.google.com/d/msg/object-composition/-/jRF8nw9s928J>
> >>>>> .
> >>>>> To post to this group, send email to object-composition@**googlegroup*
> >>>>> *s.com <object-co...@googlegroups.com>.
> >>>>> To unsubscribe from this group, send email to object-composition+**
> >>>>> unsubscribe**@googlegroups.com<object-composition+unsubscribe@googlegroups. com>
> >>>>> .
> >>>>> For more options, visit this group athttp://groups.google.com/**group
> >>>>> **/object-composition?hl=en<http://groups.google.com/group/object-composition?hl=en>
> >>>>> **.
>
> >>>>>  --
> >>>> You received this message because you are subscribed to the Google
> >>>> Groups "object-composition" group.
> >>>> To view this discussion on the web visithttps://groups.google.com/d/**
> >>>> msg/object-composition/-/**5TrwtYSyio8J<https://groups.google.com/d/msg/object-composition/-/5TrwtYSyio8J>
> >>>> .
> >>>> To post to this group, send email to object-composition@**
> >>>> googlegroups.com <object-co...@googlegroups.com>.
> >>>> To unsubscribe from this group, send email to object-composition+**
> >>>> unsub...@googlegroups.com<object-composition%2Bunsubscribe@googlegroups. com>
> >>>> .
> >>>> For more options, visit this group athttp://groups.google.com/**
> >>>> group/object-composition?hl=en<http://groups.google.com/group/object-composition?hl=en>
> >>>> **.

James O Coplien

unread,
May 2, 2012, 4:03:18 PM5/2/12
to object-co...@googlegroups.com
Use cases are about business logic, more or less independent of the interface strategies used to implement it. That's MVC land: MVC separate interface (windows, mice) from logic (business data, business procedures).

DCI separates the use case logic (sequencing) from the underlying data and other infrastructure that is more or less accidental complexity that arises from mapping the solution onto a computer.

I think your discussion here mixes the two, and that makes it a bit hard to follow.
Reply all
Reply to author
Forward
0 new messages