Re: "How do you arrive at classes?"
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Now, a student asked me: ?How do you arrive at classes??,
Thank you all for your answers!
I have written a German-language web page to answer
the question. Here are some parts of it in English:
1. direct, literal, straightforward answer
You write several different class declarations,
when you need to have objects of different types,
and library classes do not fit all of them.
2. remarks
- There is not a unique ?best? solution
- OOP is about objects, not about classes
3. hints
- prefer to reuse a standard library class or a library
class instead of writing a new class declaration,
or at least try composition with library classes
- find fields (variables) that belong together and
group them into one class, than add methods for them
- investigate whether a class becomes more readable when
split into multiple classes in a reasonable way.
- try to isolate ?driver-like? behavior in
separate classes (?isolate change?), e.g.,
a JavaFX program is split into classes that
only contain JavaFX-related stuff and classes
that only contain JavaFX-unrelated stuff (model).
- try to see if real objects of the problem domain
can be used as objects in the program
4. further hints
- Read sources (books, articles) about OOA/OOD
- use software design patterns (see the books)
- apply software design rules (e.g.: ?KISS?)
- With anonymous innner classes and method literals
we do not need as many class declarations as in
1995 in Java
http://www.purl.org/stefan_ram/pub/klassen_java