5

I'm hoping there's a book or something out there for me to get...

If I have a class that has Collection as an instance variable, what is that method of coding called? A design pattern? If so, where can I find more information on it? As I've been working with this mentor, he's really helped me understand my programming weakness and that weakness is thinking in terms of collections or relationships between objects. It just seems so difficult for me right now and I need to read to become smarter. My mentor is a great guy, but I'm starting to feel like I need to learn more on my own.

public class Evaluation
{
    private List<Criterion> criterion = null;

    public Evaluation()
    {
        criterion = new List<Criterion>();
    }
}

4 Answers4

26

Composition

it's not a design pattern, it a fundamental practice of OOP

(as opposed to having your class inherit from the collection class)

4

My mentor is a great guy, but he gets frustrated when I start asking lots of questions, so I'm starting to feel like I need to learn more on my own.

Can I suggest that you should be reading books too.

And writing code, making mistakes, etc.

The importance of the last cannot be underestimated. Asking questions, reading books, etc can give you the false impression that there is a "perfect solution" to every IT problem and you should never be satisfied until you've found it. In reality there are lots of solutions; many of them "good enough" and none (*) of them are perfect in the long term. You need to learn to make your own practical judgements, and you will do that by doing, not by asking / reading.

(* I'm probably exaggerating a bit, but not when you take the long view. Solutions that would have been judged as "almost perfect" / "state of the art" by the standards of the 1960's are now judged as old fashioned, unmaintainable and unscalable. Only a fool would confidently predict that the IT world won't continue to evolve. Objective perfection is probably only achievable for problems that are so simple that it hardly matters.)

Stephen C
  • 25,388
  • 6
  • 66
  • 89
2

Encapsulation, a form of Information Hiding

In this example, the object has some internal state information (a List that you have named criterion).

Jay Elston
  • 2,750
2
  • Composition: An object that can own one or more objects of another type or its own type is said to be "composed" of those objects. Ownership is important here - it means that when the lifetime of the composing object ends, so do the lifetimes of the composed objects.
  • Aggregation: An object that refers to one or more objects of another type or its own type is said to "aggregate" those objects. The difference with composition is ownership: if the aggregating object's lifetime ends, the lifetimes of the aggregated objects are not (necessarily) affected.