I learnt to program in the top down procedural system (assembly). Knowing
when to create a new function was easy. If you kept repeating the same task
then you needed to put it in a subroutine. But I'm a bit confused by all
these classes in Java. What criteria should I use to decide to create a new
class instead of just add a method to my existing class. I can see me
writting code thats basically one big class with lots of methods. I know I
should break it up into smaller classes but cant tell what criteria to use.
Can anyone recommend a book or url for an object orientated approach to
programming?
Thanks in advance
> I learnt to program in the top down procedural system (assembly). Knowing
> when to create a new function was easy. If you kept repeating the same task
[quoted text clipped - 7 lines]
>
> Thanks in advance
Bruce Eckel had written a free e-book on the subject a while back, but
after searching it seems you may have to buy the latest version (which
may not be a bad idea), or if you want the 2nd edition it is available
free at: http://www.janiry.com/bruce-eckel/
MC - 06 Feb 2006 08:34 GMT
Thanks for your help I'll try the ebook first, I just want a basic model for
thinking in objects. This looks just the ticket
> I learnt to program in the top down procedural system (assembly). Knowing
> when to create a new function was easy. If you kept repeating the same task
[quoted text clipped - 7 lines]
>
> Thanks in advance
MC:
Programming languages such as Java and C++ are object-oriented
programming languages that are much different than procedure-oriented
programming languages such as C, Pascal, and FORTRAN.
When you switch from a procedure-oriented programming language to an
object-oriented one, you need to change the way you think about
developing the application. You basically model real-world objects,
that is, objects have attributes and behavior.
For example, think about developing a cell phone application. A cell
phone's attributes will include things like the color of the keys, the
kind of displays, etc. A celll phone's behaviors will include how it
makes/receives phone calls, etc.
The class mechanism in Java and C++ allows you to define attributes and
behavior for a particular object.
You should create a class to essentially focus on what that object
should be doing. Creating one *large* class with lots of methods is a
big design no-no since it makes it difficult to predict all possible
behaviors of related objects. This also makes your application
difficult to maintain.
Design patterns were developed as "templates," i.e., a set of
interacting classes, that can be applied in recurring software
situations. There are a couple of books that would be useful:
Design Patterns - Elements of Object-Oriented Software
Erich Gamma, et. al.
Head First Design Patterns
Elisabeth & Eric Freeman
http://www.wickedlysmart.com/
You can download a copy of my introductory Java and/or C++
presentations that I conduct at an annual computer show. Each one has
the same object-oriented section. Just go to http://tcf.redlich.net/,
and click on "Downloads."
Hope this helps...
Mike.
~~~~~~~~~~~~~~~~~~~~
ACGNJ Java Users Group
http://www.javasig.org/
~~~~~~~~~~~~~~~~~~~~
MC - 06 Feb 2006 08:43 GMT
MC - 07 Feb 2006 14:56 GMT