I am taking a Course in VB.NET and my greatest stumbling block is working with classes.
Is there a systematic way of deciding what should go in a particular class?
I don't think I have come to appreciate the beatuy of coding this way, can anyone help me out?
I have several books and have read online tutorials that simply mention how to create Classes, Methods, Stuctures...etc, but I would like to know how I would go about designing what goes in what class.
Here is what I get stuck on. Take a look at the attached file, it is a copy of my lab. I know I am to build some simple console editor, but uses classes and objects makes no sese to me.
Here is what I don't get.
When you see the diagram, why am I making these classes, how do I know what I am overloading or overriding?
dunno what you quite mean but I'll have a go. The lab exercise calls for a simple editor, now any editor comprises several elements (objects) which make it work - it has a working document, that document will contain text and maybe some features that will allow you to format that text - paragraphs, return characters and the like. To make an OOP editor program you would want to write each component I have described above as individual units. That way you can modify each unit to you hearts content. For example you might want to make a paragraph in your document a little more indented - the document does not need to understand how you go about coding this, it just recognizes the instruction to insert a new paragraph and lets the paragraph unit decide how much it will indent.
The diagram in your lab simple describes the relationship between these units (objects) and how they will interact.
Terms like overload, interface etc are simply techniques used to implement OOP projects.
Any specific questions give me a shout and I'll be happy to help
Thanks for the help. I am slowly getting this stuff. It was all so easy when you just droped a control on a form and told it what to do. I will continue to study this stuff.
Thanks for the offer for help.... believe me ... we will be in touch.
I think my problem with OOP is not the code or design, rather than the approach to the problem. For example the lab I posted earlier. Can anyone describe the thought process as to which objects will be needed, what will be a child object, why we need a base classs ...etc...
I have searched for an article or something to describe the reasoning when learning how to approach OOD and I have found nothing more than definitions of Classes, Methods, Blah, Blah, Blah.
your lucky i am at work and have ALL the free time i need to reply
There is no hard and fast rule as to overall OOP/OOD (well none that I know of anyway despite what others may say). There are guidelines of course and some techniques work better than others in certain situations. If their was a prescribed way of doing OOP then all programmers could just read one book, practise a little and then rule the world...basically different situations call for different approaches. Never listen to ANYONE that says '...you should do it this way' without offering a reason as to WHY you should. This is one of my pet programming hates!!
I have to minimize and then maximize my window now to simulate a busy day at work . Tune in later i'll provide you with some simple, clumsy (but useful starting points).
PS. I programmed procedural style for an age before getting introduced to OOP - I sat like a rabbit in a headlight before it eventually made some sense.
My own favourite OOP/OOD ‘contrived example’ is this:
Look at a TV set, it is an object right…it has a user interface (the remote), an output device to describe events that goes on inside (the screen), it comprises a whole set of child objects (transistors, tube, power supply etc) that we are not expected to have access to and which cannot really function outside of the parent object. Each of these child objects does not care what the other one does but is reliant on it none the less. For example, to increase the volume the volume control will interact with the speakers. They react to changes in the volume via the volume control but do not care how the control achieves this. A TV might also feature inheritance concepts – the power supply might be adapted to serve various electrical components inside the TV that require different levels of voltage (ok, using transistors but I think you get the idea).
If you were a TV designer you would be expected to save as much money manufacturing costs as you could. Therefore you would reuse certain components a volume control might also serve as a great on/off switch with a little tweaking here and there (inheritance)…BINGO you’ve saved the company the expense of developing separate controls, one for the volume and one for the on/off.
This is the basis of OOP/OOD. Look at the big picture (the TV) and think of the bits that make it work (the electrical components inside), think how you might be able to re-use elements of your design (the volume knob as a on/off switch) using interfaces or inheritance. Now in your lab do the same, could a paragraph object (child) be anything without the document (parent), could the document be anything without the window displaying it...etc, etc. So sit down and look at TV, the best way to pick up OOP.
Anything else just give us a shout. Writing this sure beats programming for a living
Between readon the useless info on the net and my class, along with the information provided on this forum I have finally have a grasp on this whole OOP concept.
However, I am still trying to finish my assignment. I think I have created the classes correctly. I have tried to create everything according to the UML diagramm, but I am not certain how to create the Paragraph Class or the Document Class, I think I have to use Arraylists but I am not sure how the methods within the Classes.
I am not too worried about the Main Module apart from how to use the Document and the Paragraph Class
I have attached the following files:
-The Lab Description (Diagram Included)
-My prof's demo, that is not complete
-My program up to date.
If someone could take a look and let me know If I am going in the right direction, or offer some advice it would be greatly appreciated.