Tuesday, April 23, 2024
03:11 PM (GMT +5)

Go Back   CSS Forums > CSS Optional subjects > Group I > Computer Science

Reply Share Thread: Submit Thread to Facebook Facebook     Submit Thread to Twitter Twitter     Submit Thread to Google+ Google+    
 
LinkBack Thread Tools Search this Thread
  #1  
Old Tuesday, January 22, 2008
Janeeta's Avatar
Member
 
Join Date: Dec 2006
Location: Karachi
Posts: 96
Thanks: 26
Thanked 121 Times in 39 Posts
Janeeta is on a distinguished road
Default Classes and data abstraction

Classes are the second form of structured data type in C++, and they are what makes C++ an object-oriented language. A class combines both the data, similar to the members of a struct, and the operations you can perform on that data. Unlike structs, a class presents up to three levels of access to the members (public, private, and protected). Members of a class may be public and accessible to the users of the class. Private members of a class are only accessible within the class, and all members are private by default. When you declare a variable of a class type, you are declaring an instance of the class, also called an object. You use the dot operator (.) to access members of a class, much like when accessing members of a struct. By default, the only operation defined for classes is the assignment operator. You may define functions that have classes as parameters, and you can pass them as either reference or value parameters.
Classes carry functionality with the data contained in the class. It is not uncommon for a class to have no public data members, only methods (operations on a class) and properties (in C++ these are usually void functions, either a void return or void parameter function). The overall process of restricting data from the users of your classes is called information hiding, and it is part of the overall abstraction process. One of the goals of object-oriented designs is to remove the unimportant details from the view of those using the objects, which enhances the integrity of the data in the object by preventing direct manipulation. There are two special members of a class, the constructor and the destructor. The constructor is called whenever an instance of the class is instantiated, and the destructor is called whenever an instance is destroyed, either automatically or explicitly. You may develop many constructors for different types of input parameters. The default constructor has no parameters, but you may change this to a function with parameters that all have default values.

Static members of a class create a level of persistence similar to a static variable in a function. If a static data member or function is also publicly visible, the static member can be called directly by a user of the class without using an instance of the class. Static data members of a class are shared across all instances of the class, which can conserve memory for key data structures, but it can introduce undesirable interactions between seemingly independent objects. A static function cannot access non-static data members of the class unless the access is through a local variable in the function.

The overall process in object-oriented design works toward creating Abstract Data Types, which are general purpose abstractions. A complete ADT defines all of the data and the methods you can perform on that data. The implementation details are hidden in cases where the ADT is not provided as a full-source kit. One final thing to remember is that classes by themselves do not create executable code; rather, when you compile a program that uses classes, the code defined by the class is included in your program.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Statistics and Probability obaidkhan Statistics 3 Friday, August 23, 2013 02:51 PM
Notes and Topics on Statistics Faraz_1984 Statistics 23 Saturday, June 04, 2011 07:08 AM
Solved Everyday Science Papers Dilrauf General Science & Ability 4 Friday, April 08, 2011 06:10 PM
Mobile codes nice051 Computers and Technology 4 Monday, December 10, 2007 09:56 AM


CSS Forum on Facebook Follow CSS Forum on Twitter

Disclaimer: All messages made available as part of this discussion group (including any bulletin boards and chat rooms) and any opinions, advice, statements or other information contained in any messages posted or transmitted by any third party are the responsibility of the author of that message and not of CSSForum.com.pk (unless CSSForum.com.pk is specifically identified as the author of the message). The fact that a particular message is posted on or transmitted using this web site does not mean that CSSForum has endorsed that message in any way or verified the accuracy, completeness or usefulness of any message. We encourage visitors to the forum to report any objectionable message in site feedback. This forum is not monitored 24/7.

Sponsors: ArgusVision   vBulletin, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.