What's the best way to learn programming??

ok well in many cases the need for inheritance isn't there.
you only really need inheritance if you want to make many different types of a basic object, e.g vehicles, books, etc.

there are 2 ways you can make use of inheritance this is taken mainly from java:
implementing:
this is where you implement an interface. an interface just defines what methods and variables a subclass MUST contain.
extending:
this is where you extend a base class. a base class can implement methods which can then be used by subclasses. you can also make abstract classes where some methods aren't defined - subclasses have to define them.

in C/C++/(i think)C# interfaces are classes where all methods are pure virtual (http://en.wikipedia.org/wiki/Pure_virtual_method), abstract classes are ones with pure virtual methods and defined methods.
subclasses can also chage the definition of methods using polymorphism (http://en.wikipedia.org/wiki/Polymorphism_(computer_science))

back to classes:
you use them to modularise your code e.g. for the game of life mentioned above, i had a class which was a cell on the grid, a class that was the grid which contained an array of cells. my cells extended jlabel (java.swing) and the board extended jpanel.

the benefit of this is:
my cells had all the methods jlabel provides and i could also add my own thus providing me with lots of functionality without writing duplicate code.


that is the main thing really, it stops you duplicating lots of code, and lets you modularise everything so it is easier to maintain.

if you have any more questions, just ask

daven

[edit]lol so many posts in the time it took me to write mine!!
 
Last edited:
Thanks again for replying guys. I understand much better now and will spent most of tomorrow just writing different classes and wrapping my head around their different uses. I had a quick look on Microsoft's site and found an Absolute Beginners series of media helping noobs like me get started.

http://msdn.microsoft.com/vstudio/express/visualcsharp/learning/default.aspx

For anyone else just starting out.

I'll be sure to check back with any issues that arise (and they will).
That Game of Life looks very cool and I would love to be able to write something like that in the near future.
 
Back
Top Bottom