|
SortaCore wrote: testUser = Array.IndexOf(new string[] { "mrock", "kasante" }, Environment.UserName.ToLower()) != -1;
If you want to get a little tighter about it:
testUser = Array.Exists(new [] { "a", "b" }, t => t=="a");
First of all, you don't need string[] because the compiler can infer the array type.
Second, using "Exists" makes it clearer to the reader what you're doing, especially since you're not interested in the index, you just want to know of the value exists.
Lastly, the use of the predicate t => t == 'a' means you could do some fancier things if you wanted later on -- it's a more general purpose solution. (Where 'a' would actually be in your case Environment.UserName.ToLower()
Marc
|
|
|
|
|
We all understand what a "class" is and what an "instance" is. These terms have nice rigorous definitions. We are having a debate in school with one of the professors. Of course we have to follow there definition in that class but we are wondering what the real answer is. It seems like there are 3 possible answers.
1. An Object and Class mean the same thing.
2. An Object and Instance mean the same thing.
3. An Object is both a Class and Instance. Object is more of a higher order term that includes both.
After doing some web research it seems that over time the name has changed. Just referring to common usage. It started out in the 80's as the first choice. In the 90's things got confusing so they added the word class so they could deal with hierarchies of classes. After the turn of the century is looks like it moved mostly to the 2nd definition. Still it kind of still oscillates between 2 and 3. Some of us think we should not even use the word object because of the confusion and only use class and instance.
We are wondering what the rest of the world thinks now.
So many years of programming I have forgotten more languages than I know.
modified 14-Nov-13 14:53pm.
|
|
|
|
|
Don't think belong here, see the forum header description.
|
|
|
|
|
Where should it go? I could not find anything closer. I considered Design and Architecture but that seems to be more technical questions where this one is more general and philosophical. Looking at the other posts this group seemed more serious than Lounge.
It is kind of Weird and Wonderful how names change.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
I've always chosen the definition "an object is the instantiation of a class" or "an object is an instance of a class"...
Therefore a class is the mere definition, prototypes...
The instantiation is a relationship between the object and the class, it's an action that represents saving memory space and create a new object of that class there.
And the object is that already instantiated class in memory.
At least this is how we manage our programs in the company
|
|
|
|
|
The traditional answer is, "it depends what you're talking about"!
- In .NET, there is a type called System.Object[^]; I believe Java has a similar type. When referring to that type, you are referring to a class. [#1]
- When you refer to "an object", you are usually referring to an instance of a class. [#2]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well, I would say your first bullet point is not equivalent to the OP's #1 (i.e. a class in general). Instead in this context Object is a specific type, which would be an additional 4th definition.
Regarding you second bullet point I agree. Before .NET I always considered an object to be an instance.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Back when I was in school, I fretted over what was a procedure and what was a function... and what is the difference, is one technically more correct than the other for any given language...
When I got a job, school didn't matter anymore.
|
|
|
|
|
I am suck in school and fretting trivial BS. At least this time is an MS (More of the Same).
Why? Because employers want it. I often wonder if they know what they want it for . Still, they pay extra money for it .
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
My 2c
A class defines the properties of some object.
An instance is a single individual instance of a class.
So you talk about a customer object, meaning any instance of the customer class.
Or you talk about a particular customer instance.
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
An interesting twist on the word. I have seen it stated another way though rarely. The more general statement is an object is a set of one or more instances. I am not sure I like this definition. I would prefer to talk about classes and sub-classes.
A class is much more than just properties. It is also methods. Methods that can modify the properties. Methods that can extract other meanings from the properties.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
Actually, technically speaking, classes are methods and fields, and nothing else.
Properties are a compiler feature, after the compiler they don't exist anymore (take a look at compiled code in ILSpy). The properties are turned into get_PropertyName and set_PropertyName style methods.
So, getting to the core of the issue...
An object has two meanings, first it is a base class from which all .NET "things" derive (and why they can all be cast to object). The second meaning is everything is an "object" in the sense that they are something you can interact with.
So, everything is an object, and objects are anything in .NET.
Read this[^]
Right under where it would show the inheritance tree it says "All classes, structures, enumerations, and delegates.".
|
|
|
|
|
michaelbarb wrote: an object is a set of one or more instances
I don't like that at all!
I think it just depends on the circumstances which sounds more natural (to me);
"If we add this property to the Customer class"
"We'd need to save the Customer object to the database"
"That instance needs to be saved to the database"
So object is really more generic than instance.
michaelbarb wrote: A class is much more than just properties. It is also methods.
Sure, of course - I meant properties in a generic sense - Properties, methods, constructors, events, references interface implementations etc. etc. are all just properties of an object - like diameter, colour and the ability to bounce are all properties of a ball.
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
Wrong forum.
Mostly 3. Definitely not 1 or 2.
In my opinion... "object" is not strictly a technical term, but a very high-level concept, analogous to "thing". Some object may be defined in some language as a class , a struct , a collection , whatever.
Like "data structure" on steroids.
|
|
|
|
|
Object is unit of storage in computer memory - it is simple concept that means it has size and address: that is all folks you need to know what object is. Most of us keep forgetting that we program box filled with wires, transistors, diodes etc.
Class is template of data type (includes both fields and functions) and it is programming abstraction of real world problem it attempts to solve.
Class that has been created or instantiated takes shape (becomes an object that you can "touch", talk to - meaning send and receive messages, move, delete etc.) in computer memory that the program can work with.
There should not be any confusion what object is among programmers. Unfortunately most programming books is using some weird concepts and examples regarding OOP which confuses everybody and it is not even funny.
|
|
|
|
|
If you study the original papers about object oriented programming you will find that PIEBALDconsult is closer to their view. I think most programming books have followed this concept. It is a little harder and more abstract to understand. Over time things have changed and the word object more often attached to a an instance as you state. Because of all the confusion about the word "object", it continues to be an ambiguous term. The only unambiguous software terms are "class" and "instance".
Wow, you can touch something in computer memory. Are you kind of like Tron? . . . I a apologize for my sarcasm I just could not help my self.
To be really exact there are two kinds of instances. There are virtual instances that exist in computer memory. There are physical instances that you can really touch and maybe even eat. For Thanksgiving I think I will stay with a physical turkey. I will be full but I will bet you will still be hungry after eating a virtual turkey.
I also at times have trouble separating the physical and virtual worlds . I keep having to remind myself they are different. Maybe someday physical and virtual instances will merge.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
There is no ambiguity. If you forget to instantiate your programming abstraction i.e. create memory storage you will get execution error stating that memory object cannot be found (exact wording depends on the sense of humor of the compiler programmer).
Not all languages will use class or instance as a valid term. Most of the confusion stems from academics who cannot program and do not understand underlying technology but can write poetry and create log and confusing lectures on something very simple.
PiebaldConsult is very generic and incorrect in my opinion.
|
|
|
|
|
Academics "create long and confusing lectures on something very simple" 50/50 shot. Not at all sure about that poetry thing.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
Object is a universal term that can be applied to any level of abstraction.
It can be an instance of a class, a smartphone, a record in a database, a document, an archive of documents and a pixel on your screen. But an object can also be other things like a rock, an animal or a song.
A rock doesn't have to fit in the classification systems that scientists created and a song doesn't have to fit in the artist/genre system that the music industry has created. These objects are not (strictly) instances.
So every instance is an object, but not every object is an instance.
Instances always come from classes, but objects don't have to.
Objects can also be born out of chaos.
.
|
|
|
|
|
0bx wrote: Object is a universal term Probably the most "correct" explanation I've come across. At least IMO ... which is probably the problem, there's no "opinion" shared by everyone. At best it's shared by most, though that particular "object" is hard to find.
To turn this into a specific programming simile. To me the value inside the RAM position pointed to by an un-initialized pointer is still an "object" even though it might have no meaning in any form of any class inside the program. It certainly isn't an "instance" of any of them, except if by random chance it was.
|
|
|
|
|
michaelbarb wrote: Of course we have to follow there definition in that class but we are wondering what the real answer is.
Which is one of numerous complaints about education - they don't teach you how to think, they teach the wrong things, etc. How much more fruitful it is to actually explore what object, class, and instance actually mean!
So, to you question, I realized a long time ago that when writing articles and teaching OOP, there is a lot of sloppiness regarding object and class, and very few people actually even use the term "instance." So here's my definition.
A class defines a type on which operations can be performed and which also describes its relationship with other classes. Relationship is very important!
An object is an instantiation of a class. Note the use "instantiation", related of course to the word "instance", but I want to avoid the specificity of the term "instance".
I try to use the word "instance" when I refer to a specific object. We can think of objects as abstract (not the way OOP uses the term abstract) instantiations, such as a "User object". But I'll use the word "instance" when I refer to a specific, instance of an object, such as "the 'Marc Clifton' User instance."
What I have found confuses developers (both noobs and experienced devs) is when "object" is used to refer to both a class and an instance - in fact, some very smart people I know fail to make the distinction and this can lead to all sorts of design / architecture problems when they don't realize that there is a distinct difference between the definition of a class (ie a type) and its instantiation.
So, that's my 2c.
Marc
|
|
|
|
|
Thinking in C++;Bruce Eckel
Object is unit of storage in memory that has type, size and address so it can be referred to, copied, deleted, moved or act upon; it can send/receive messages (using functions).
Class is programming abstraction of real life problem. Class is a design template and design concept of a compound type that has to be put to work by assigning memory space for variables and function code. Once class is instantiated in the memory it becomes object (or objects with multiple instances or through inheritance, polymorphism etc.). At this moment class transitions from programming abstraction to reality (object) because it executes on the hardware for the desired effect.
|
|
|
|
|
Member 10088171 wrote: Object is unit of storage in memory that has type, size and address so it can be referred to, copied, deleted, moved or act upon; it can send/receive messages (using functions).
I disagree. Mr. Eckel is confusing an instantiation with its behavior. An object cannot inherently send/receive messages unless the class defines that behavior. Furthermore, some objects cannot be copied, deleted, moved, etc. A class doesn't need to provide any behavior at all - it can simply be a container for public fields! And lastly, and object does not have a type. If you look at memory in C++, can you distinguish between an integer and a double? No. In languages that support reflection, yes, one can determine the type of an object because somewhere there is a "database" of what object in memory is associated with what definition (the class, aka the type.)
So, with all respect, Mr. Eckel doesn't know what he's talking about.
The rest of your quote (I assume it's a quote) is also flawed.
Member 10088171 wrote: Once class is instantiated in the memory it becomes object
What about classes with static methods? These don't require instantiation. Are they objects or classes?
Marc
|
|
|
|
|
Instantiated is not equivalent with application programmer action. In case of static methods and fields the compiler does it in the background. At the runtime it is occupying memory and it is an object as well and integral part of OOP.
Object has a type defined by its class and at the core of OOP is compound type consisting of fields and functions (if any as you pointed out).
Sizeof operator will distinguish between int and float/double and C++ has features that are similar to reflection (RTTI). In fact anything you do in any language post C++ is C++. You are just not aware of this because certain complexities of C++ are hidden from modern programmer and rightly so.
Object is occupying memory and each and every object can be copied, moved etc. Just give me pointer to it.
What is confusing for most programmers? Programming abstraction which is class that does not exist unless object is created based on class design meaning that chunk of memory for data and code is assigned and then executed on the hardware. The designer creates classes but the actual work is done by objects residing on hardware.
I do not mind disagreements but to my astonishment none of the posts above was concrete enough to correlate programming abstraction with constrains of underlying hardware. This only confirms that the mumbo jumbo written in most programming books on OOP is truly confusing and able to fool experienced programmers.
|
|
|
|
|
Object is an heavily overloaded term.
So, let's try to put things into perspective.
"Object" was first introduced as a CONCEPT, as in Object-Oriented Programming. In this model, you have "stuff", which we'll call objects, that implements a program structure and logic merging procedures AND data on the same "thing". Or object, so to speak. In this new paradigm, we call procedures as Object Methods, and data as Object Properties, linked together as it makes more sense (before this the paradigm said you have code structured in procedures that manipulates data, which existed independently).
Then, based on this conceptual model, a lot of really smart people created computer languages.
Each one of them used this new paradigm as it seemed fit to solve problems.
So "objects" morphed into Classes, Instances, hierarchy, etc.
But, let's face it: Object sounds a lot better than Instance or Class, so, sometimes, people used the abstract concept of object to refer to something that was actually implemented (like Bruce Eckel in the quote from before).
So, the answer to "what is an object?" is: Anything that has Methods and Properties, merging those two really different things.
Really, really simple.
You're asking the wrong question: An Object is NOT a Class, nor an instance.
Exactly like as a function is not an Algorithm. A function can implement an Algorithm, pulling the concept into the "real world", even if not in a tangible form.
But in some languages a Class IS an object (e.g. if you have static methods and properties).
In .NET, both classes and class instances are Objects.
In Python, EVERYTHING is an object.
Conclusion: it's more a matter of asking the right questions.
|
|
|
|
|