473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Difference between object and variable?

<e-mail address deleted>
Dec 24 '10 #1
8 11584
weaknessforcats
9,208 Expert Mod 8TB
Nothing.

Variable is C/C++ program language terminology.

Object is Object Technology terminology (you know, the UML folks).

You will appear more as a programmer if you use variables and structs.

You will appear more as an object design person if you use objects and classes.
Dec 25 '10 #2
Rabbit
12,516 Expert Mod 8TB
A variable holds a single piece of data while an object holds many variables and methods that act on those variables.
Dec 26 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
[quote]A variable holds a single piece of data while an object holds many variables and methods that act on those variables.[/qute]

The C Programming Language page 6 says: A C program whatever its size, consists of functions and variables.

The same is true for C++.

Both C and C++ languages create variables the same way: Allocate memory for the data. Keep the values unchanged unless directed by a function.

A method is an Object Technology term for an operation on a class using member variables. C++ does not use methods. It uses functions instead. The function arguments are variables. The class of C++ is a struct. The member functions of a C++ class are just functions with a pointer argument for the variable.

Write a C++ program using a class and get it working. Then change the class keyword to struct and rebuid the program. Nothing will happen. The code will compile and link as before.

C++ is not an object oriented language like Java. It does not support the Liskov Substitution and that makes C++ no object-oriented. Istead, it is a structural language derived from C that has object-oriented-like features added.
Dec 26 '10 #4
Rabbit
12,516 Expert Mod 8TB
Those are concepts that are debated amongst computer scientists on what is truly considered object oriented languages.

Liskov substitution is not something that can be supported by the implementation of a language, it must be supported by careful design of the objects. Take for example a rectangle class, a subclass of that would be a square. Regardless of which language is used, if setter methods are used, it is in violation of the Liskov substituion principle.
Dec 26 '10 #5
weaknessforcats
9,208 Expert Mod 8TB
The Liskov substitution is supported by Java and C#.

But not C++. The principle requires that a derived object can be substituted for a base object. C++ lets you substitute a pointer or reference of the derived object for a pointer or reference to a base object but you cannot substitute the object itself.

This has nothing to do with accessor methods.
Dec 27 '10 #6
Rabbit
12,516 Expert Mod 8TB
If you have a Rectangle class in Java and create a Square subclass, you're saying that you can use the Square subclass in place of a Rectangle class without running into any problems?

If we use the formal definition of the Liskov Substitution Principle, which states that "Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T," then the rectangle/square example is not compliant with LSP. Yet, it can be implemented in Java. LSP is not a feature of a language but a feature of carefully designed classes and subclasses.
Dec 27 '10 #7
weaknessforcats
9,208 Expert Mod 8TB
Okay. So Rectangle has a draw property. Therefore,
draw(Rectangle object) draws a Rectangle. The substitution principle says that if Square derives from Rectangle, then substituting a Square object in
draw(Rectangle object) draws a square.

This works in C# but not C++. In C++ you need to use virtual functions plus pass not the object to the draw but only the address of the object. Note that a C++ reference (which as works here) just passes the address of the object. If you try substituting the derived object for the base object in C++ you get slicing.
Jan 2 '11 #8
Rabbit
12,516 Expert Mod 8TB
A typical example that violates LSP is a Square class that derives from a Rectangle class, assuming getter and setter methods exist for both width and height. The Square class always assumes that the width is equal with the height. If a Square object is used in a context where a Rectangle is expected, unexpected behavior may occur because the dimensions of a Square cannot (or rather should not) be modified independently. This problem cannot be easily fixed: if we can modify the setter methods in the Square class so that they preserve the Square invariant (i.e. keep the dimensions equal), then these methods will weaken (violate) the postconditions for the Rectangle setters, which state that dimensions can be modified independently. Violations of LSP, like this one, may or may not be a problem in practice, depending on the postconditions or invariants that are actually expected by the code that uses classes violating LSP. Mutability is a key issue here. If Square and Rectangle had only getter methods (i.e. they were immutable objects), then no violation of LSP could occur.

As you can see, LSP is a property of an implementation of a class. Not a property of a language. While a language may allow you to substitute one subclass for a parent class, it does not make the implementation of that class LSP compliant. The ability to make a substitution is not what LSP states. What LSP states is that you can make the substitution and every method will work as expected as if the parent class is being used.
Jan 3 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Joe Blow via DotNetMonster.com | last post by:
Hello, I have a design problem involving class instances as global variables. To give you my background, I've programmed lots in Java, and most of it has been large class structures. I'm...
8
by: Lauren Quantrell | last post by:
I get the following error: "Object variable or Width block variable not set error" trying to run this in my Access2000 .ADP database: CurrentDb.Properties.Append...
0
by: RJN | last post by:
Hi Sorry for posting again. I'm calling a shared method in the class. The following error is found in production though I'm not able to reproduce. ...
6
by: Neo Geshel | last post by:
I am trying to deal with an image in code-behind. I consistently get the following error: Server Error in '/' Application. Object variable or With block variable not set. Description: An...
3
by: Richard Hollenbeck | last post by:
I've marked the line in this subroutine where I've been getting this error. It may be something stupid but I've been staring at this error trying to fix it for over an hour. I'm pretty sure the...
9
by: axs221 | last post by:
I am trying to move some of our large VBA Access front-end file into ActiveX DLL files. I created two DLL files so far, one was a module that contains code to integrate into the QuickBooks...
1
by: abhijmenbumca07 | last post by:
Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
4
by: BrianAdev | last post by:
Why It throw an error of <Object variable or With block variable not set> set objAccess = GetObject(strMdbPath) objAccess.DoCmd.SetWarning False objAccess.DoCmd.OpenReport strReportName, 0 'It...
3
by: Newbie19 | last post by:
I'm trying to get a list of all subfolders in a folder on a share drive, but I keep on getting this error message: Object variable or With block variable not set. Description: An unhandled...
1
by: 55555 | last post by:
what is difference between variable type and object type??
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.