Questions tagged [instance]

In object-oriented programming an instance is an occurrence or a copy of an object, whether currently executing or not.

Instances of a class share the same set of attributes, yet will typically differ in what those attributes contain. For example, a class "Employee" would describe the attributes common to all instances of the Employee class. For the purposes of the task being solved Employee objects may be generally alike, but vary in such attributes as "name" and "salary".

Related tags:

5388 questions
20
votes
2 answers

EC2 server, lots of micro instances or fewer larger instances?

I was wondering which would be better, to host a site on EC2 with many micro instances, or fewer larger instances such as m1.large. All will sit behind one or a few larger instances as load balancers. I will say what my understanding is, and anybody…
Jd007
  • 201
  • 2
  • 6
20
votes
6 answers

Why can't one put type signatures in instance declarations in Haskell?

I like to put type signatures for all top-level definitions in my code. However, type signatures in instance declarations don't seem to be allowed, and if I put one I get a "Misplaced type signature" error from GHC. Why is this so? Why can't GHC…
Prateek
  • 2,377
  • 17
  • 29
20
votes
5 answers

Ruby on Rails - Access controller variable from model

I am trying to access an instance variable which is set in the controller in the model. The controller is the products controller and the model is the products model. The instance variable is a instance of another model called account. The instance…
RailsSon
  • 19,897
  • 31
  • 82
  • 105
20
votes
2 answers

ambiguous class with namespace names in 2 dlls

I've imported 2 dlls to my application (third party) Now both of them have a namespace with same name. For example A.B and in both of them there is a class again with a same name. Now I want to create an instance of one of them, but because the…
Mehrdad
  • 2,054
  • 3
  • 20
  • 34
20
votes
2 answers

Instance new Type (Golang)

Can anyone tell me how to create a new instance of Type from a string? Reflect? There are examples but they are for the older (pre Go 1 versions) of the language [:(]
Accex
  • 351
  • 1
  • 2
  • 11
19
votes
3 answers

SPARQL: Get all the entities of subclasses of a certain class

I've to get all the instances of a class C and subclasses (direct or indirect) of C, in SPARQL. I can get all the direct subclasses of C in this way: SELECT ?entity WHERE { ?subclass rdfs:subClassOf :C . ?entity rdf:type ?subclass . } But I…
auino
  • 1,644
  • 5
  • 23
  • 43
19
votes
5 answers

Java Reflection: get instances of a given class found by entering its name?

Is it possible to get all instances of a class by entering this class's name as a string? Something like this? var instances = Reflection.findClass("com.someone.MyClass").getInstances(); Any feedback is appreciated. Thanks.
Tom
  • 8,536
  • 31
  • 133
  • 232
19
votes
2 answers

Single instance of class in Python

I am creating a Python application that includes socket communication with a server. I would like to have a module which can be used throughout my entire application (several other modules). Currently my module look like this: class…
user3170354
  • 391
  • 1
  • 4
  • 11
19
votes
2 answers

Instance variables vs parameter passing? Is there an argument?

So, I have been working on re-factoring some legacy code recently and have found myself questioning the validity of some of the re-factoring decisions I have been making. One such query has been about the use of instance variables for object sharing…
Roja Buck
  • 2,354
  • 16
  • 26
19
votes
2 answers

Why won't dynamically adding a `__call__` method to an instance work?

In both Python 2 and Python 3 the code: class Foo(object): pass f = Foo() f.__call__ = lambda *args : args f(1, 2, 3) returns as error Foo object is not callable. Why does that happen? PS: With old-style classes it works as expected. PPS:…
6502
  • 112,025
  • 15
  • 165
  • 265
19
votes
7 answers

NSClassFromString returns nil

Why does NSClassFromString return nil ? As per the definition it has to return class name. How should I take care to rectify this problem? I need to instantiate a class from string and call the method, which is in the class, using the instance…
suse
  • 10,503
  • 23
  • 79
  • 113
19
votes
8 answers

Inheriting from instance in Python

In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example: A = Parent(x, y, z) B = Child(A) This is a hack that I thought might work: class Parent(object): def…
Alexandra
18
votes
4 answers

C# : how to - single instance application that accepts new parameters?

I'm creating a (C#) program that downloads binaries using NZB files, there may only be one instance of my application running at any time. So when a user doubleclicks an .nzb-file and my program is not running, it should start and process it (easy,…
Led
  • 2,002
  • 4
  • 23
  • 31
18
votes
8 answers

Comparing two instances of a class

I have a class like this public class TestData { public string Name {get;set;} public string type {get;set;} public List Members = new List(); public void AddMembers(string[] members) { …
Dumbo
  • 13,555
  • 54
  • 184
  • 288
18
votes
2 answers

Flutter Instance member ‘{0}’ can’t be accessed using static access

I am passing variables from one activity to another in flutter but getting the error "Instance member ‘latitude’ can’t be accessed using static access" I need it converted in that block so I can assign it to a static URL. class Xsecond extends…
Mark
  • 425
  • 1
  • 4
  • 19