search

src/lab/util/Printable.js

1// Copyright 2016 Erik Neumann. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the 'License');
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an 'AS IS' BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15goog.provide('myphysicslab.lab.util.Printable');
16
17/** An object that has a minimal string representation via its {@link #toStringShort}
18method.
19
20When writing a `toString` method, use `toStringShort` on objects that are Printable.
21This is mainly needed to avoid infinite loops, such as when an object prints a
22{@link myphysicslab.lab.util.Subject} or {@link myphysicslab.lab.util.Observer}.
23
24This can also make printing an *array of Printable objects* more practical because we
25only print minimal identity information, rather than the full `toString` representation
26which would have too much information and be unreadable.
27
28* @interface
29*/
30myphysicslab.lab.util.Printable = function() {};
31
32/** Returns a minimal string representation of this object, usually giving just identity
33information like the class name and name of the object.
34
35For an object whose main purpose is to represent another Printable object, it is
36recommended to include the result of calling `toStringShort` on that other object. For
37example, calling `toStringShort()` on a DisplayShape might return something like
38this:
39
40 DisplayShape{polygon:Polygon{'chain3'}}
41
42@return {string} a minimal string representation of this object.
43*/
44myphysicslab.lab.util.Printable.prototype.toStringShort;