Is there a generally accepted symbol for indicating instantiation. That is indicating an object is an instance of a class.

My first guess is to use a left arrow with a double or triple line but this seems more like a functional programming symbol, based upon what I've seen of Haskell.

Wikipedia has no examples and a quick google for psuedocode mostly turns up simple functional or procedural algorithms. Object Orientated examples don't seem to feature or do not use any specific symbol.

  • $\begingroup$ This was originally asked on TeXExchange $\endgroup$ – Carel Nov 2 '16 at 11:31
  • $\begingroup$ Welcome to CS.SE! Thanks for letting us know about the cross-post. However, cross-posting isn't allowed. Please do not post the same question on multiple sites. Each community should have an honest shot at answering without anybody's time being wasted. I suggest you pick one community where you want the question to appear, and delete the other copy. $\endgroup$ – D.W. Nov 2 '16 at 18:43
  • $\begingroup$ I've decided to give comp sci a shot at answering this first, the TeX Exchange guys seemed to think it was a better fit for here. $\endgroup$ – Carel Nov 2 '16 at 18:48

In most contexts, objects are values and classes are types, so I would simply use the colon, representing the "has type" relation:

$Object : Class$

That said, this depends on your context, and whether $:$ carries some other meaning. You could also use $\in$, since you can identify a class with the set of objects that are instances of that class.

  • 1
    $\begingroup$ Be careful in the presence of subtypes and subclasses -- this might or might not mean what you want it to mean. Suppose C is a class and D is a subclass of D. Suppose O is an instance of D. Then both O : D and O : C would be valid (since O can be validly be given the type C). The same comments apply to subtyping. For this reason, it's probably a good idea to define what you mean by your notation explicitly. $\endgroup$ – D.W. Nov 2 '16 at 20:08
  • $\begingroup$ @D.W. I'm a bit rusty on my OO theory. So in your example, if we did O = new D(), we would say that O is an instance of D but not C, even though both $O:D$ and $O:C$ hold through subsumption? $\endgroup$ – jmite Nov 2 '16 at 21:00
  • 1
    $\begingroup$ I'm afraid I'm a bit rusty too. I don't know whether it'd be normal to call O an instance of C in that case. I hope someone else here knows more. Here's some terminology I think I remember seeing in some PL papers: If we declared a variable as as C x; and then assigned x = new D(); I have a recollection that we might say "the runtime type of x is D" but that "the statically declared type of x is C" -- the latter is a statement about the declared type of the variable x; the former is a statement about the (most-specific) runtime type of the value stored in that variable. $\endgroup$ – D.W. Nov 2 '16 at 21:09
  • $\begingroup$ My actual use case is in documenting test functions in a table, specifically testIsInstance and testNotInstance. O:C and O:Dwould then be valid representations of the former even if D is a subclass of C, and a striked colon could represent the latter. I'm using ∈ for sets. Perhaps O:(D<C) or O:D(C) could be used to represent the appropriate hierarchy in more explicit cases. It seems odd that there doesn't appear to be a formalized set of symbols/notation. $\endgroup$ – Carel Nov 3 '16 at 22:59
  • $\begingroup$ Actually I ended up going with \circ as \not: just looks awful and \circin normal math indicates function of which one could imagine maps to Instance of. At a push I suppose one could use \circ and \cdotas compliments.. $\endgroup$ – Carel Nov 3 '16 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.