Many 14

Posted by tottinger Fri, 23 Mar 2007 16:01:00 GMT

We’ve talked about Zero, and One, so all that’s left of the big Three Numbers is “many”.

Many is more than one. More than one object that must be used in the same way, more than one implementation of an algorithm, more than one implementation of an interface. An API wrapper implemented once for production, and once for testing is Many. One real object and one mock is Many.

Many gives power to the Liskov Substitution Principle. If there are many (more than one) objects to be used in the same way, then it is imperative that an interface is created for them so that they may be used interchangeably (transparently) by the client.

Many objects of the same interface (“type”) may be used one-at-a-time (by reference) or in groups (containers and loops). We don’t write code that calls A and B and C in the same way because that would be “three” and we don’t believe in 3. We believe in Many. It’s a loop over a list. If we’re treating the objects similarly, we should exalt the similarity by putting them in a loop, rather than stress individuality by coding two statements for making the call.

By the way, don’t confuse Many with “two things with similar structure”. Many refers to “more than one thing with similar usage” in the LSP-compliant sense. It doesn’t demand that you create base classes to capture some essential similarities, only that you create interfaces and loops as required.

In a multi-generational GC, the theory is that some things by nature have short lifespans, and others by nature have long lifespans. Most objects are created and deleted, and a few may make it to the third-generation cache where they’re almost never examined (comparatively) for collection. Many has a similar theory. Objects that occur once are singular things, but once they start to multiply they are expected to multiply more in the future. Not only does the “interfaces & loops” keep the code clean, it recognizes the Many things as an extension point in the code. That’s double-benefit if we listen to our code as it goes from one to many.

Trackbacks

Use the following link to trackback from your own site:
http://blog.objectmentor.com/articles/trackback/6108

Comments

Leave a response

  1. Avatar
    Stan 41 minutes later:

    I first read zero-one-many when working closely with a system that had hard coded COBOL tables to a length of 7 in hundreds of modules because 7 insurance contracts fit on the green screen. In fact, most people have one or two contracts, but a few have ten and a couple groups slipped in with hundreds. Changing the system to use anything but 7 would have been … well it’s been 20 years and it never happened.

    Yesterday I changed one of my classes from 2 inputs to n inputs and it was a major overhaul because I coded 2 instead of many the first time.

    So I read zero-one-many first as related to building data structures. Reading it as polymorphism is new to me and very interesting. Thanks!

  2. Avatar
    Stan 42 minutes later:

    I first read zero-one-many when working closely with a system that had hard coded COBOL tables to a length of 7 in hundreds of modules because 7 insurance contracts fit on the green screen. In fact, most people have one or two contracts, but a few have ten and a couple groups slipped in with hundreds. Changing the system to use anything but 7 would have been … well it’s been 20 years and it never happened.

    Yesterday I changed one of my classes from 2 inputs to n inputs and it was a major overhaul because I coded 2 instead of many the first time.

    So I read zero-one-many first as related to building data structures. Reading it as polymorphism is new to me and very interesting. Thanks!

  3. Avatar
    Criminal Records over 4 years later:

    Most objects are created and deleted, and a few may make it to the third-generation cache where they’re almost never examined (comparatively) for collection.

  4. Avatar
    Tenant Screening over 4 years later:

    So I read zero-one-many first as related to building data structures. Reading it as polymorphism is new to me and very interesting.

  5. Avatar
    SEO Firm India over 4 years later:

    hey man,i am a first time visitor here and like your blog.

  6. Avatar
    Robert Schlee over 4 years later:

    There exists obviously a whole lot to find out about this. I think you created some excellent points in Attributes also. Keep operating, excellent work!

  7. Avatar
    okey oyunu oyna over 4 years later:

    very good…

    Okey oynamak hiç bu kadar zevkli olmadi. Online ve 3 boyutlu okey oyunu oyna ve turnuvalara sende katil.

  8. Avatar
    hancy over 4 years later:

    It’s a lucky day!I get one pair of women heels from http://www.aliexpress.com/fm-store/908014 ! It’s have beautiful appearance and very comfortable! Here’s your first look at the first Women’s Heels that I have ever seen. I do believe this is the first time our store has released a Women’s Heels in a high top form.

  9. Avatar
    cathy over 4 years later:

    Thank you for posting. Waiting for updating.

  10. Avatar
    balmain dresses over 4 years later:

    thanks for share with us

  11. Avatar
    belstaff jackets over 4 years later:

    thanks for share with us

  12. Avatar
    belstaff jackets over 4 years later:

    thanks for share with us

  13. Avatar
    Cheap Jordan over 5 years later:

    555sql The longest road, step by step, also can go through, again a short road, not feet march cannot be reached.

  14. Avatar
    iPhone contacts backup over 5 years later:

    Many of them. It is true.Well. Though I am not a good application developer. And I need do more hard work to improve myself. When I come to here. I know that I have come to the right place to learn something I need. Thanks for your good advice. And I will do the practice as possible as I can. Thanks.

Comments