Architecture : Why do we need request data-structure ? alternative

87 views
Skip to first unread message

w3bj...@gmail.com

unread,
Feb 12, 2015, 10:37:58 AM2/12/15
to clean-code...@googlegroups.com
Hello all,
Here is an alternative to request data-structure. The idea is simple : Allow two component to communicate with each through interfaces.
What are, according to you, the differences between two such approaches ? Why should we prefer one over the other ?

Here is a simple code example :

// using request data-structure :

void start(){
   
/* code... */

   
Request* next_action = request_provider.get_next();

   
if (next_action instanceof Add){
        // blahblah
   
}else if( ){
 
   
/* code... */
}



//using interfaces

void start(){
   
/* code... */
   
    request_provider
.tell_next_action_to(this);

   
/* code... */
}

// where this implements :
interface request_executor{
   
void add(int id, string name);
   
void do_smth();
   
// etc.
};


Frédéric Bouquet

unread,
Feb 12, 2015, 10:47:27 AM2/12/15
to clean-code...@googlegroups.com
Hi,

I would prefer this third idea :

void start(){
Request next_action = request_provider.get_next();

next_action.execute();
}

Interface Request {
void execute();
}

class Add implements Request {
void execute() {
// blabla
}
}


Why this one ? Because if I want to add a new type of request, I don't
have to modify anything except of adding a new type of request :)

Hope it helps.

Cheers
> --
> The only way to go fast is to go well.
> ---
> You received this message because you are subscribed to the Google Groups
> "Clean Code Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clean-code-discu...@googlegroups.com.
> To post to this group, send email to clean-code...@googlegroups.com.
> Visit this group at http://groups.google.com/group/clean-code-discussion.



--
Frédéric Bouquet
Twitter/Github : bouquetf
http://www.espacedefouille.org/

w3bj...@gmail.com

unread,
Feb 12, 2015, 12:03:45 PM2/12/15
to clean-code...@googlegroups.com
Hello Frederic,
I'm responding to Uncle Bob's clean architecture advice where Request Datastructures are transmitted from the UI to the Interactors.

The idea behind all this is to maximize low coupling, so that the UI has no knowledge of the business rules.
When giving an execute() method to the request, it forces the UI to have knowledge about the business rules, and therefore to recompile if those rules changes. 


w3bj...@gmail.com

unread,
Feb 12, 2015, 12:05:18 PM2/12/15
to clean-code...@googlegroups.com
which is what we want to avoid !
The clean architecture I'm refering to is EBC (Entity Boundaries Interactors). 
Reply all
Reply to author
Forward
0 new messages