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
11
votes
1 answer

How to convert Object to List in c#?

I have a List in Model. When I write a html helper, I can get the data from metadata.Model, which is an object // this is from MVC3 (namespace System.Web.Mvc -> ModelMetadata), I did not write this // Summary: // Gets the value of the…
Eric Yin
  • 8,737
  • 19
  • 77
  • 118
11
votes
6 answers

Whats the point of accessing private variables through getter and setter (accessor) functions?

In classes, variables are often made private for encapsulation, and to limit the variables to a certain scope allow better error control and fewer bugs. This makes sense, as the fewer places a variable can be accessed the fewer places a bug can…
fdh
  • 5,256
  • 13
  • 58
  • 101
11
votes
3 answers

Debugging a C# Object Initializer

Does anyone have any tips for debugging exceptions in a C# object initializer block? The object initializer syntax is basically all or nothing, which can make it especially difficult to troubleshoot inside of a LINQ query. Short of breaking the…
technomalogical
  • 2,982
  • 2
  • 26
  • 43
11
votes
2 answers

How to control json_encode behavior?

Is there any way to control json_encode behavior on objects? Like excluding empty arrays, null fields and so on? I mean something like when using serialize(), where you can implement magic __sleep() method and specify what properties should be…
gremo
  • 47,186
  • 75
  • 257
  • 421
11
votes
2 answers

Extract keys from JavaScript object and use as variables

There is a method in PHP called extract which does exactly what I want to do here. Say I have an object that looks like this: var data = { name: "Olly" age: 19 }; I want to run a method like extract(data) so that I can then access the…
user1082754
11
votes
3 answers

My PHP array of references is "magically" becoming an array of values... why?

I'm creating a wrapper function around mysqli so that my application needn't be overly complicated with database-handling code. Part of that is a bit of code to parameterize the SQL calls using mysqli::bind_param(). bind_param(), as you may know,…
Rick Koshi
  • 945
  • 1
  • 11
  • 21
11
votes
2 answers

Why is this object property undefined?

Consider the code below. The first console.log correctly logs the image, and you can see its properties in the image below. However, when I try logging one if its properties to the console, I get undefined! console.log(that.data[0].cards); //works…
maxedison
  • 17,243
  • 14
  • 67
  • 114
11
votes
3 answers

Scala Best Practices: Trait Inheritance vs Enumeration

I'm currently experimenting with Scala and looking for best practices. I found myself having two opposite approaches to solving a single problem. I'd like to know which is better and why, which is more conventional, and if maybe you know of some…
Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
11
votes
5 answers

What is the difference between objects and classes in Python

I am a self-taught python user (kind of.). I read much to deepen my knowledge about python. Today I encountered a text saying: ... classes and objects .... So I was wondering what is the difference between objects and classes in python. I taught…
yasar
  • 13,158
  • 28
  • 95
  • 160
11
votes
5 answers

Can an object remove itself? How?

I'm trying to write a simple ball game, and there's several turns (ie., ball lives). The ball "dies" when it passes the bottom border of the screen. What I have so far works, but doesn't seem to be the proper way to do things: if (ball.getY() >…
Alicja Z
  • 249
  • 1
  • 2
  • 9
11
votes
7 answers

Saving a TObject to a File

How can one save an Object, in its current state, to a file? So that it can immediately be read and restored with all its variables.
David
11
votes
6 answers

Why int can't be null? How does nullable int (int?) work in C#?

I am new to C# and just learned that objects can be null in C# but int can't. Also how does nullable int (int?) work in C#?
Rusi Nova
  • 2,617
  • 6
  • 32
  • 48
11
votes
2 answers

How can I get typed Object.entries() and Object.fromEntries in Typescript?

When I use Object.fromEntries(entries) or Object.entires(obj) in typescript for my typed/const entries arrays or objt objects, I am losing the types to any or a broad type. I can manually assign generic types (e.g. Record) in some…
Aidin
  • 25,146
  • 8
  • 76
  • 67
11
votes
4 answers

trying to store java objects in contiguous memory

I am trying to implement a cache-like collection of objects. The purpose is to have fast access to these objects through locality in memory since I'll likely be reading multiple objects at a time. I currently just store objects in a java…
jbu
  • 15,831
  • 29
  • 82
  • 105
11
votes
2 answers

min heap in python

I'd like to store a set of objects in a min heap by defining a custom comparison function. I see there is a heapq module available as part of the python distribution. Is there a way to use a custom comparator with this module? If not, has someone…
Setjmp
  • 27,279
  • 27
  • 74
  • 92