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
14
votes
9 answers

Bootstrap with CKEditor equals problems

I'm trying to create a Bootstrap modal which contains an instance of CKEditor, but there are a lot of problems... So basically the fields are left unenabled, they don't look like, but I can't interact with them. Does anybody have a solution to this…
Miguel P
  • 1,262
  • 6
  • 23
  • 48
14
votes
4 answers

Making a data type an instance of Show in Haskell

I need to make the following data type an instance of Show: data Tree a b = Branch b (Tree a b) (Tree a b) | Leaf a I'm fairly new at this, but to start with, I interpreted this declaration as "We have made a new type called Tree, which is…
norman
  • 5,128
  • 13
  • 44
  • 75
13
votes
1 answer

How to organize Haskell modules with instances: stick to data type vs type class?

The general question is which module structure is more convenient when adding instances for existing objects? Which pros and cons there are? Let's say I want to add NFData instance for Seq type. I can place it in: Data.Sequence.Extra (as the same…
modular
  • 1,099
  • 9
  • 22
13
votes
7 answers

Dynamically creating an instance of a class from a string containing the class name in C++

Lets say I have a base class with 100 children: class Base { virtual void feed(); ... }; class Child1 : public Base { void feed(); //specific procedure for feeding Child1 ... }; ... class Child100 : public Base { void feed(); …
Scott
  • 131
  • 1
  • 3
13
votes
4 answers

How to wrap a static class in a non-static instance object (dynamically)

I have an interesting problem. I need to wrap static classes dynamically. I.e. return a non-static instance to my callers. e.g.: public object CreateInstance(string className) { Type t = assembly.GetType(className); if (IsStatic(t)) { …
gatapia
  • 3,574
  • 4
  • 40
  • 48
13
votes
3 answers

A standard way in C++ to define an exception class and to throw exceptions

I want to build a class with functions that may throw exceptions that I want to catch when I use it. I inherit my_exception from the standard exception class. I implement the what() function so that it returns a string that is stored in a private…
ip84
  • 190
  • 1
  • 1
  • 9
13
votes
1 answer

Create a DATETIME column in SQLite FLutter database?

I create a TABLE with some columns and everything's ok until I tried to insert a new DATETIME column: _onCreate(Database db, int version) async { await db. execute("CREATE TABLE $TABLE ($ID INTEGER PRIMARY KEY, $NAME TEXT, $COLOUR TEXT, $BREED…
Edoardo Tavilla
  • 523
  • 2
  • 7
  • 18
13
votes
2 answers

@instance_variable not available inside a ruby block?

With the following code: def index @q = "" @q = params[:search][:q] if params[:search] q = @q @search = Sunspot.search(User) do keywords q end @users = @search.results end If @q is used instead of q, the search always returns…
jakeonrails
  • 1,885
  • 15
  • 37
13
votes
1 answer

node.js - Creating instance of a class directly from require

I have a class in a seperate file. I need to create an instance of it in another file. I tried this: var connection = new require('./connection.js')("ef66143e996d"); But this is not working as I wanted. Right now I am using this as a temporary…
DifferentPseudonym
  • 1,004
  • 1
  • 12
  • 28
13
votes
10 answers

Can this Java singleton get rebuilt repeatedly in WebSphere 6?

I'm trying to track down an issue in our system and the following code worries me. The following occurs in our doPost() method in the primary servlet (names have been changed to protect the guilty): ... if(Single.getInstance().firstTime()){ …
Adam
  • 277
  • 7
  • 17
13
votes
8 answers

Can I create an object for Interface?

Is it possible to create an object for an interface? If yes, how is it done? According to my view the following code says that we can: Runnable r = new Runnable() { // some implementation }
kalepu harish
  • 139
  • 1
  • 1
  • 3
13
votes
1 answer

Free Sonar instanse for open-sourced projects

I know that for Apache foundation projects there is https://analysis.apache.org/ Is there free Sonar instance for open-sourced projects? UPDATE: ASF Sonar Instance is deprecated and removed as of 29th November 2019.
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
13
votes
4 answers

Is using Python `isinstance` ever right?

I've got a 2D array of different blocks, all inheriting from Block. I want to check if the block that I clicked on is a Dirt type block, like this: clickedblock = getClickedBlock() if isinstance(clickedblock, Dirt): place a block else: …
Name McChange
  • 2,750
  • 5
  • 27
  • 46
13
votes
4 answers

clojure instance? single argument

I am a little confused by the clojure instance? function. It seems quite happy to take a single argument. So (instance? String) works fine, but always returns false. Am I missing something here? I've done this twice in two days, and both times it…
Phil Lord
  • 2,917
  • 1
  • 20
  • 31
13
votes
6 answers

Limit instances creation of a class?

I am using C#. I have created a class which can be included in any c#.net project (desktop or web based), but I want that only 10 objects will be created in that application of my class. If object instances created more than 10 then it should give…
djmzfKnm
  • 26,679
  • 70
  • 166
  • 227