Questions tagged [object]

An object is any entity that can be manipulated by commands in a programming language. An object can be a value, a variable, a function, or a complex data-structure. In object-oriented programming, an object refers to an instance of a class.

Objects in object-oriented programming (OOP) are data structures combined with the associated processing routines. Classes are sets of objects, while objects are instances of sets. Objects have members and methods, defining their properties and their abilities. Classes can have their own members and methods, which define the properties and abilities of the set of objects. For instance, if we have a Bird class, its objects might have an age property and a fly ability, while the Bird class might have a number of birds or a migrate ability, which is applicable for the set. Class-level methods are called static, or shared. For instance, a file could be represented as an object: a collection of data and the associated read and write routines. In typical object-oriented languages, all objects are instances of classes.

Properties of an object

Three properties characterize objects:

  • Identity: the property of an object that distinguishes it from other objects
  • State: describes the data stored in the object
  • Behavior: describes the methods in the object's interface by which the object can be used

See also:

  • (Used as a template for creating new objects)
  • (Object-oriented programming)

Resource

64898 questions
292
votes
13 answers

Inconsistent Accessibility: Parameter type is less accessible than method

I'm trying to pass an object (a reference to the currently logged on user, basically) between two forms. At the moment, I have something along these lines in the login form: private ACTInterface oActInterface; public void button1_Click(object…
dodgrile
  • 3,121
  • 2
  • 19
  • 12
284
votes
5 answers

Is it possible to delete an object's property in PHP?

If I have an stdObject say, $a. Sure there's no problem to assign a new property, $a, $a->new_property = $xyz; But then I want to remove it, so unset is of no help here. So, $a->new_property = null; is kind of it. But is there a more 'elegant'…
valk
  • 9,363
  • 12
  • 59
  • 79
283
votes
3 answers

How to access (get or set) object attribute given string corresponding to name of that attribute

How do you set/get the values of attributes of t given by x? class Test: def __init__(self): self.attr1 = 1 self.attr2 = 2 t = Test() x = "attr1"
Nullpoet
  • 10,949
  • 20
  • 48
  • 65
277
votes
22 answers

Check if object value exists within a Javascript array of objects and if not add a new object to array

If I have the following array of objects: [ { id: 1, username: 'fred' }, { id: 2, username: 'bill' }, { id: 2, username: 'ted' } ] Is there a way to loop through the array to check whether a particular username value already exists and if it does…
user2576960
  • 2,883
  • 2
  • 14
  • 10
276
votes
9 answers

Converting Java objects to JSON with Jackson

I want my JSON to look like this: { "information": [{ "timestamp": "xxxx", "feature": "xxxx", "ean": 1234, "data": "xxxx" }, { "timestamp": "yyy", "feature": "yyy", "ean": 12345, …
JustTheAverageGirl
  • 2,973
  • 4
  • 17
  • 18
269
votes
5 answers

How do you programmatically set an attribute?

Suppose I have a python object x and a string s, how do I set the attribute s on x? So: >>> x = SomeObject() >>> attr = 'myAttr' >>> # magic goes here >>> x.myAttr 'magic' What's the magic? The goal of this, incidentally, is to cache calls to…
Nick
  • 21,555
  • 18
  • 47
  • 50
265
votes
22 answers

How to cast an Object to an int

How can I cast an Object to an int in java?
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
260
votes
3 answers

Why does typeof array with objects return "object" and not "array"?

Possible Duplicate: JavaScript: Check if object is array? Why is an array of objects considered an object, and not an array? For example: $.ajax({ url: 'http://api.twitter.com/1/statuses/user_timeline.json', data: { screen_name:…
Johan
  • 35,120
  • 54
  • 178
  • 293
259
votes
15 answers

Javascript reduce() on Object

There is nice Array method reduce() to get one value from the Array. Example: [0,1,2,3,4].reduce(function(previousValue, currentValue, index, array){ return previousValue + currentValue; }); What is the best way to achieve the same with objects?…
Pavel S.
  • 11,892
  • 18
  • 75
  • 113
254
votes
20 answers

String to object in JS

I have a string as string = "firstName:name1, lastName:last1"; now I need one object obj such that obj = {firstName:name1, lastName:last1} How can I do this in JS?
hijibiji
253
votes
12 answers

What is the best method to merge two PHP objects?

We have two PHP5 objects and would like to merge the content of one into the second. There are no notion of subclasses between them so the solutions described in the following topic cannot apply. How do you copy a PHP object into a different object…
Veynom
  • 4,079
  • 2
  • 19
  • 24
253
votes
4 answers

Clone Object without reference javascript

I have a big object with much data. And i want to clone this in other variable. When i set some param of the instance B has the same result in the original object: var obj = {a: 25, b: 50, c: 75}; var A = obj; var B = obj; A.a = 30; B.a =…
Enzo
  • 4,111
  • 4
  • 21
  • 33
247
votes
9 answers

C#: Printing all properties of an object

Is there a method built into .NET that can write all the properties and such of an object to the console? One could make use of reflection of course, but I'm curious if this already exists...especially since you can do it in Visual Studio in the…
Svish
  • 152,914
  • 173
  • 462
  • 620
245
votes
27 answers

How to remove undefined and null values from an object using lodash?

I have a Javascript object like: var my_object = { a:undefined, b:2, c:4, d:undefined }; How to remove all the undefined properties? False attributes should stay.
JLavoie
  • 16,678
  • 8
  • 33
  • 39
237
votes
8 answers

How do I correctly setup and teardown for my pytest class with tests?

I am using selenium for end to end testing and I can't get how to use setup_class and teardown_class methods. I need to set up browser in setup_class method, then perform a bunch of tests defined as class methods and finally quit browser in…
avasin
  • 9,186
  • 18
  • 80
  • 127