Hello,

I would like to know how people in Pharo ecosystem do to deal with object
wiring, as described by Marting Fowler in
https://martinfowler.com/articles/injection.html#FormsOfDependencyInjection:

"A common issue to deal with is how to wire together different elements:
how do you fit together this web controller architecture with that database
interface backing when they were built by different teams with little
knowledge of each other."

He gives an example, I will leave it in java as it is simple enough to
understand:

"class MovieLister...

  public Movie[] moviesDirectedBy(String arg) {
      List allMovies = finder.findAll();
      for (Iterator it = allMovies.iterator(); it.hasNext();) {
          Movie movie = (Movie) it.next();
          if (!movie.getDirector().equals(arg)) it.remove();
      }
      return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]);

  }"

The question is how to provide the finder object in a decoupled matter, a
naive approach would be:

" private MovieFinder finder;

  public MovieLister() {
    finder = new ColonDelimitedMovieFinder("movies1.txt");

  }"

Which couples the MovieLister to the specific ColonDelimitedMovieFinder
 class.

Fowler explains how to decouple using an IoC framework or a Service
Locator. In Java and .Net IoC is used most of the time. I Googled how this
problem is approached in Smalltalk/Pharo, and I generally I found answers
"that is easy to do in Smalltalk, so there is no need of a framework", what
I miss is a description on *how* to do that:

https://stackoverflow.com/questions/243905/smalltalk-and-ioc
https://stackoverflow.com/questions/2684326/is-there-a-dependency-injection-framework-for-smalltalk
https://stackoverflow.com/questions/243905/smalltalk-and-ioc/347477#347477

I know that in Smalltalk I can make MovieLister to receive, upon
construction, a class representing MovieFinder and call it construction
message. As long an object that responds to this message is provided, I can
create as many derivations I want and the MovieLister will be decoupled
from the MovieFinder. That way, however, I still have to wire things by
hand, and I am not sure if this is what I am supposed to do in order to
solve the decouple problem.

Can you explain me how this is done in Pharo? It's is usually wiring by
hand? Is there a simple construction that deals with the wiring problem
that I cannot foresee?

Thanks in advance,
Vitor

Reply via email to