Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: "How do you arrive at classes?" Date: Wed, 14 Jan 2015 20:29:29 +0100 Lines: 68 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net oqo9QAJCEOOGejm3rNQWrA5zZdZK2NuLSiFQeEFMG1umwgbwc= Cancel-Lock: sha1:/zMmvYa9rkEW35HBLrKpcaXB7QQ= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:30711 On 14.01.2015 18:40, Joshua Cranmer =F0=9F=90=A7 wrote: > On 1/13/2015 10:57 PM, ram@zedat.fu-berlin.de (Stefan Ram) wrote: >> I tried to answer the question =C2=BBHow do you arrive at >> classes?=C2=AB in the classroom, kind-a stuttering, because >> I was not prepared for this question. Now, I am curious: >> How would /you/ answer this question? > > The shortest answer is "there is no one true way to do this." Right. > A longer response: > The primary point of object-oriented programming is to break the state > up into a series of objects each responsible for managing its own state= =2E > Keeping that in mind, a class is a collection of state and its > manipulators that can be reasoned about independently of the rest of th= e > program. As you work through and design the system and its API, classes= > will tend to fall out naturally as things that just make sense to exist= =2E =2E.. if you have some experience. > A caveat is that ultimately the purpose of design is to produce the mos= t > maintainable program. Not always: if it's a one off or there are other goals much more=20 important (e.g. performance) then maintainability can be sacrificed with = good reasons. > Sometimes, things are so simple that adding > classes makes the code less, rather than more, maintainable. An example= > is parsers: if you're parsing a complex programming language like Java,= > you'll want to have a distinct Parser class. But if you're parsing > something as simple as an RFC 822 address string, you'll probably want > to make it a method. Simple here does not mean lines of code (the latte= r > parser is ~500 lines of code and one using the former framework is ~700= > lines of code, both including very copious comments), but is rather the= > utility and reuse of state between methods. Absolutely agree. > Another caveat is that there is room for reasonable disagreement: two > different answers on what are classes in a particular applications can > both be right. That hints to that "right" and "wrong" are probably the wrong categories = to judge a design. :-) Cheers robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/