OOP and other such advanced things
Why would you use classes and linked lists and all these things I hear about don't get me wrong I know how to use classes and how they work but I just don't under stand why you would use them.
that's why c++ is out here today
well classes helps people to do object oriented programming making their classes access their objects not other functions and oop helps you keep code nice and clean. Linked lists just need a bit of typing but when you know you can make anything possible its better than an array an array is fixed you can change it but a linked list can shrink and grow and can be as big as you want it. any more questions.
so what your saying is...
so all classes are for is to make things look nicer (well you know what I mean) and I just wasn't sure about linked lists thinks though I'll have to read into to those, but another question in a class whats the point in makeing things private?
private and protected
well it's like a microwave all the bits and pieces are protected by the box that's like functions in classes other external functions access the class functions and the class functions access the details
it's like there's were no protected for the microwave you could easily wreck it. With class functions it's good to protect all the objects like ints and that so only class functions can access them. That way you don't have functions accessing the same class al the time and it keeps the code clean
Programs that are designed in an object oriented way are much easier to maintain and more flexible when you want to extend programs.
I don't know about anybody else, but OOP and using classes helps me program more logical code. It's easy to ask:
- What kind of data am I working with?
- What can and should happen to this data?
- What can't and shouldn't happen to this data?
- Who needs to know what?
Then you take all that and ball it up into a number of classes and voila. The structuring part is easy after that because you know what to do and already how to do it.
Also, writing member-functions seems alot easier b/c most of the data is directly accessible, so you don't have to worry about passing and checking arguments.
Just my opinion
Classes = Good, three main benefits as I see it -
1) Notational convenience - often a class' access to it's own data makes functions less cumbersome. Also, overloading the << operator for a class can make code simpler to read.
2) Multiple objects - multiple instances of a class can have their own sets of data members, so you dont have to go making new large scope variables if you make another instance of something.
3) Reuse - A class can be more easily ported into another program, and extended upon by inheritance
Linked lists - Inferior to STL in all regards. (IMO) Basically a linked list or an STL vector is an array that is automatically resized to fit in more data.
private: - Separate the implementation from the interface. private vs. protected only applies to inheritance.
Object orientation is a way of thinking. In C you're thinking about functionality, what should the program do? In C++ you're thinking in terms of information. Which information is relevant? What classes should need which information and which classes shouldn't have access to certain information.
Passing and checking arguments is still required. If an instance of class A wants to change data of class B it should call an interface function of class B which checks if the data that A wants to pass is valid.