Re: software design question

From: Josiah Carlson (jcarlson_at_nospam.uci.edu)
Date: 02/08/04


Date: Sun, 08 Feb 2004 11:04:36 -0800


> Almost. I want to write software from components. I want a simple, yet clear
> and effective interface for the components to communicate with eachother.
> The components will be dynamically loaded. If available they have to fit
> like a piece in a puzzle, if ther're unavailable all related functionality
> will be unavailable - *not* raise exceptions or cause program abortion,
> etc.

Design your interface, and write your program around your interface.
Here's one:

#main
import submodule

class data_storehouse:
     pass

passer = data_storehouse()
passer.error = None
passer.main = main
#etc.

def caller(*args, **kwargs):
     passer.args = args
     passer.kwargs = kwargs

     submodule(passer)
     if passer.error:
         #handle the error

This is essentially another user was doing with their "Singleton()"
interface, though they created a bottom-level module to hold all
application-wide information.

> I simply cannot pass all components to all others, because I don't yet know
> which components there might be.

So you only pass the ones you know about when writing your application.
  When functionality A gets created, before component B, likely
functionality A won't require component B. If you discover later that
it does, then you modify functionality A to use component B. You can't
magically get away from this.

> Having a single global name space is poor software design. It makes you not
> having to think about "inter module communication", because there is none
> to take care of, because you can call virtually everything from everywhere.

Of course it is. It also doesn't scale very well, though Python
namespaces (dictionaries) don't seem to have issues with pollution, it
can get unweidly to handle.

>>There is another kludge:
>
> [...]
>
>>I would suggest you just put everything into a single file. 500 lines
>>is not that large. Heck, a few thousand isn't even that bad, as long as
>>you pay attention to what you are doing and use an editor with a
>>browsable source tree/class heirarchy, and comment liberally.
>
> Wow! You can't seriously suggest this as a software design recommendation!

The kludge, no. That's why I called it a kludge. You can propagate
namespaces without a problem, and you don't even have to worry about the
Python import mechanisms. It ends up with the same functionality as
having a single module, without having a single module.

> Importing the complete namespace from one module into another is exactly
> what will cause you fourty hours of debugging code afterwards.

I never said it was a good idea.

> Do you think there is a reason why in Java every class got to be put into
> one source file - or is this just a bad language restriction?
> Don't get me wrong, I'm not critisizing Python here.

I don't know, I never thought about it, because I never learned Java. I
was in the last year they taught C/C++.

Thinking about it now, I think it is a poor language restriction. Being
able to have a half-dozen classes with related functionality in a single
module is /very/ convenient. Check out the threading or itertools
modules. Imagine having to use threading.Thread.Thread or
itertools.imap.imap, those would be annoying and useless bubbles.

> A <==> B
>
> Suggestion 1:
>
> A1 ==> B ==> A2
> A1 ========> A2
>
> Suggestion 2:
>
> A2 ==> B2 ==> A1 ==> B1
> A2 =========> A1 B1
> B2 =========> B1

You can still end up SOL if A1 requires functionality from A2. You
still have a circular dependency. As the sibling reply by John Roth says,
    "this doesn't always work in practice. Another term for hierarchical
    design is layered architecture. The rule in a layered architecture is
    'call down, notify up.' It's the higherlayer's esponsibility to call
    down to install callbacks so that the lower layer can notify up at
    run time."

John says the truth.
  - Josiah



Relevant Pages

  • Re: multiple inheritance
    ... slice" of functionality, and use MI to get at it from a class that has this ... to think much more about the design at this level than any most programmers ... I'm a MI AND Interface fan. ... Point 1: Aggregation ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Great SWT Program
    ... orthogonal to whether or not a program has a decent user interface. ... A few also knew the arrow keys existed. ... "useful functionality required to qualify the application as an IDE". ... Or maybe you simply use "real text editor" as a synonym for IDE; ...
    (comp.lang.java.programmer)
  • Re: When would you use an abstract class and when an interface?
    ... An abstract class is useful when you need a substantial amount of ... An example of where an interface is useful is where you have unrelated ... items that need to provide some similar functionality in a uniform ... but where the system caches them to disc as well as HTML ...
    (comp.lang.php)
  • Re: Ensuring a method exists
    ... When different classes offer similar functionality and you want ... Interface types are more flexible than class types because the former ... (defgeneric rem (collection object)) ... It's left up to the responsibility of the programmer to define the right methods, or to leave them out when they are actually not necessary. ...
    (comp.lang.lisp)