![]() |
|
#1
|
||||
|
||||
Object Oriented Programming?I missed my class about this object oriented programming...I read over the notes but he uses statements that I don't really understand.
Can anyone explain what object oriented programming is in just a few lines? (or translate this into...lamens terms i suppose) This is what my prof said... "Decomposition of the problem domain into a set of collaborating abstract data types (i.e., classes), each of which encapsulates mutable states that can only be accessed via a well-defined ADT interface. It is often argued that the paradigm of object orientation results in abstractions that map naturally to concepts in the problem domain, and supports graceful evolution of software through encapsulation. " And another question...looking through his example of OOP, he has this array. Okay, he's got this "Guarded Array" and this "Managed Array". And the code is as follows: CPP / C++ / C Code:
CPP / C++ / C Code:
And he made this new type of array which uses the guarded array module CPP / C++ / C Code:
and the implementation... CPP / C++ / C Code:
The thing i'm confused about is the " : array() " in the code ManagedArray::ManagedArray(unsigned N) : array() (which is clearly in the code just above) What does that do and how does this initialize the array? I think he tried explaining it by "When a constructor is invoked, C++ semantics dictate that the constructors of member fields are called prior to the beginning of the constructor body. Usually, the default constructors of the member fields are invoked in such cases. Programmers may override this behavior, and explicitly select the constructors to be invoked on the member fields by using an explicit member initializer ": field(...)". " But I can't even begin to understand what that means...any help is very much appreciated. Jake |
||||
|
#2
|
||||
|
||||
Re: Object Oriented Programming?i forgot to include that array () is declared in the private section of the GuardedArray class (first code i pasted)
and in the private section of the ManagedArray class has "GuardedArray array;" |
|
#3
|
||||
|
||||
Re: Object Oriented Programming?I have no idea why your instructor is making this so complicated...Object-oriented programming should be fairly simple. C++ uses a data structure called a class, which contains functions and variables. In addition, those functions and variables may be declared public (they can be accessed anywhere in your program) or private (they may only be accessed by the class they belong to). A class is a sort of data type, like an integer or a boolean. Instances of classes are called objects. Classes also must have constructors: functions in that class which initialize the variables. Here is an example class:
CPP / C++ / C Code:
Now this is how we would use the above code in our program: CPP / C++ / C Code:
The output should look like this: 0 5 Meow. 3 6 Meow. I hope that sort of helps you understand object oriented programming. If you need any more help, my email address is gamer_2k4@yahoo.com. |
|
#4
|
||||
|
||||
Re: Object Oriented Programming?Quote:
His proffesor is doing a good job. His explaining the why as well as the how. Many times, the why is much more important. If you understand a subject, you can take it along to the next programming language. To the OP : Here is an instructive link : Object-oriented programming in C Kobi. __________________
It's actually a one time thing (it just happens alot). |
|
#5
|
||||
|
||||
Re: Object Oriented Programming?okay well forget about the object oriented aspect of this thread...i kinda understand it now so it's fine
But I still really would like to know the last part of my first post... The thing i'm confused about is the " : array() " in the code ManagedArray::ManagedArray(unsigned N) : array() (which is clearly in the code just above) What does that do and how does this initialize the array? I think he tried explaining it by "When a constructor is invoked, C++ semantics dictate that the constructors of member fields are called prior to the beginning of the constructor body. Usually, the default constructors of the member fields are invoked in such cases. Programmers may override this behavior, and explicitly select the constructors to be invoked on the member fields by using an explicit member initializer ": field(...)". " If anyone could explain this...THANKS lol |
|
#6
|
||||
|
||||
Re: Object Oriented Programming?Hi Jack,
Here is some information: Quote:
I found this from a site: It's a standard C++ way of initializing a class member. For simplicity: CPP / C++ / C Code:
would have the same net result than: CPP / C++ / C Code:
However, if you change the class to: CPP / C++ / C Code:
then trying to do: CPP / C++ / C Code:
would result to an error, since m_value is now constant and cannot be modified at runtime. The only way to give this const value a value is: CPP / C++ / C Code:
You can also use base-class constructor and initialize more variables, for example: CPP / C++ / C Code:
What you're doing is initializing the members or parent class using a constructor notation. For example, if you had a class like this: CPP / C++ / C Code:
You could then initialize it in a derived class using the constructor notation: CPP / C++ / C Code:
For simple data types such as int, it's basically the same as an assignment statement, but the constructor notation really shines when you're dealing with objects, and especially with inheritance. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#7
|
||||
|
||||
Re: Object Oriented Programming?Quote:
For example, Quote:
Just a thought. __________________
Start Programming with Python-A beginner's guide to programming and the Python language. ------------- Common Sense v2.0-Striving to make the world a little bit smarter. |
|
#8
|
||||
|
||||
Re: Object Oriented Programming?Quote:
We don't agree here. The original poster will some day encounter thechnical books and there will be no one to make the point simple for him. Maybe his boss will prefer "big words", perhaps his cutomers or clients ... It is important that students encounter problems such as this one while at university. Kobi. __________________
It's actually a one time thing (it just happens alot). |
|
#9
|
|||
|
|||
Re: Object Oriented Programming?Jake
Quote:
Actually, it's called a constructor initializer list. The initializer list allows you to initialize members and superclasses before the code of the constuctor is executed. An example: Code:
calling new foo(10) will initialize x with the value 10. Since int is not a class, this is called a pseudo constructor. Code:
calling new bar("hiya") will initialize s with "hiya". Code:
in this las example (multiple inheritance) we make sure that before the constructor code is executed both super classes are initialized and that our private member is initialized. |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read/ Write EXCEL files using C/C++ programming | confused_pig | C++ Forum | 4 | 25-Nov-2005 01:27 |
| [Tutorial] GUI programming with FLTK | dsmith | FLTK Forum | 10 | 03-Oct-2005 16:41 |
| GUI programming | crystalattice | C++ Forum | 5 | 14-Sep-2004 13:17 |
| gxx linker accepts only 7 object files | danielxs66 | C++ Forum | 1 | 12-Dec-2003 10:27 |
| How do I access an object from inside another object? | JdS | MySQL / PHP Forum | 5 | 10-Jun-2003 09:51 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The