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
2 answers

__str__ function of class ported from rust to python using pyo3 doesn't get used in print

I am using the pyo3 rust crate (version 0.11.1) in order to port rust code, into cpython (version 3.8.2) code. I have created a class called my_class and defined the following functions: new, __str__, and __repr__. TL;DR: The __str__ function…
fdsa
  • 113
  • 1
  • 6
11
votes
4 answers

Is there a benefit in using old style `object` instead of `class` in Delphi?

In Delphi sane people use a class to define objects. In Turbo Pascal for Windows we used object and today you can still use object to create an object. The difference is that a object lives on the stack and a class lives on the heap. And of course…
Johan
  • 74,508
  • 24
  • 191
  • 319
11
votes
2 answers

How can I call MemberwiseClone()?

I'm confused about how to use the MemberwiseClone() method. I looked the example in MSDN and they use it trough the this keyword. Why I can not call it directly as other objects' methods like GetType() or ToString()? Another related method that does…
mjsr
  • 7,410
  • 18
  • 57
  • 83
11
votes
5 answers

Can set any property of Python object

For example, this code is Python: a = object() a.b = 3 throws AttributeError: 'object' object has no attribute 'b' But, this piece of code: class c(object): pass a = c() a.b = 3 is just fine. Why can I assign property b, when class x does not have…
pero
  • 113
  • 4
11
votes
3 answers

Django 'model' object is not iterable

I have a table which shows me the employees registered. I want to generate a simple HTML page according to their DB which includes their name, id, designation, etc. To do so, I pass an id to the view so it can get the respective user's details and…
Talha Murtaza
  • 324
  • 1
  • 2
  • 17
11
votes
2 answers

Coverting a Boolean object array to boolean primitive array?

I have an ArrayList of type Boolean that requires to be manipulated as a boolean[] as I am trying to use: AlertDialog builder; builder.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() { ... }); However,…
Kaiesh
  • 1,042
  • 2
  • 14
  • 21
11
votes
9 answers

Creating my own "integer" object in Python

Essentially I want to be able to do something like: a = Integer(1) a += 1 print a And of course printing the number two as result. What methods do I need to create to get this behaviour in my Integer class? Disclaimer: I'm not planning to use this…
Johanna Larsson
  • 10,531
  • 6
  • 39
  • 50
11
votes
4 answers

Linux: controlling where `ld` searches for .o object files?

Ok, this is the situation: I'm trying to use some older software: works fine on Ubuntu Lucid, fails on Natty. So, I straced around a bit, and it turns out that this software calls ld, and ld eventually fails with: .../ld: crt1.o: No such file: No…
sdaau
  • 36,975
  • 46
  • 198
  • 278
11
votes
1 answer

When does Element.getClientRects() return a collection of multiple objects?

Each time when I call Element.getClientRects(), it returns a collection of only one DOMRect object. When does Element.getClientRects() return a collection of multiple DOMRect objects? function handleClick() { …
Roman Roman
  • 807
  • 9
  • 26
11
votes
6 answers

PHP method scope binding

I am confused by how PHP call method in parent-children hierarchy. Here is the code class A { private function foo() { echo "A!"; } public function test() { $this->foo(); } } class C extends…
Nero
  • 1,555
  • 1
  • 13
  • 28
11
votes
5 answers

Javascript Array of Instances of a class

In JS, I have a class called player which is: class player { constructor(name) { this.name = name; } } and I have two instances of it, called PL1 and PL2: const PL1 = new player ('pl1name'); const PL2 = new player ('pl2name'); I…
Shahriar
  • 1,855
  • 2
  • 21
  • 45
11
votes
7 answers

Serializing a javascript class object?

The requirement is simple. Here's a class... class myobj { constructor(var1, var2) { this.var1 = var1; this.var2 = var2; } addThemUp() { return this.var1 + this.var2; } } Now I make one of these... var…
IamPancakeMan
  • 199
  • 1
  • 10
11
votes
4 answers

Is there a way to set object keys from array value in one line

say I have an array like this: const myArray = ['HP', 'QP', 'PS']; And I'd like to have an object whose keys are myArray's values like { HP: 0, QP: 0, PS: 0 } Is there a way to do the following in one line: const myObj = {}; myArray.forEach(item…
t3__rry
  • 2,817
  • 2
  • 23
  • 38
11
votes
3 answers

C# Object Constructor - shorthand property syntax

A few months ago I read about a technique so that if there parameters you passed in matched the local variables then you could use some short hand syntax to set them. To avoid this: public string Method(p1, p2, p3) { this.p1 = p1; this.p2 =…
Schotime
  • 15,707
  • 10
  • 46
  • 75
11
votes
2 answers

How do I store an php object in a MySQL table?

I have set up a table that has only one field for a BLOB (Binary large object) but when I try to Insert it into the table it throws an error stating that it failed to convert the object to a string. This is my Query: mysql_query("INSERT INTO objects…
nkcmr
  • 10,690
  • 25
  • 63
  • 84