Lasso Soft Inc. > Home

Types & Objects

This chapter briefly introduces the fundamental concepts behind Lasso's type system. It describes what types and objects are and how they relate to each other, how objects maintain state, and how that state is manipulated through data members and member methods.

It also describes how types can be extended through inheritance and traits. See the chapter Defining Types for detailed information on the syntax used to create a type, and the chapter Defining Traits for information on how to create and use traits.

  • Types explains what a Lasso "type" is

  • Inheritance describes how Lasso objects are extended through inheritance

  • Traits explains what traits are and how they are used to extend types

Types

Lasso is an object-oriented programming language. In Lasso, every piece of data is an object and each object of said to be of a specific type. In many cases either the word object or type can be used to describe a piece of data. However, to be specific, the word type is used to describe a set of identically structured objects and the word object is used to describe an instance of a particular type. For example, the integer 1 is an object containing the value 1 and this object is an instance of type integer. The integers 1, 3 and 90000040 are each individual objects of type integer.

Types (and thus objects) consist of data members and member methods. A method is an executable piece of code that has been assigned to a type. To execute a member method, one must first have an instance of the type that contains that method. Every instance of a particular type will have the same set of member methods. A data member is another object contained by a type. Data members represent the unique state of a particular object and member methods are used to manipulate that state.

When a type is created, the developer chooses a name for the type. This name uniquely identifies that type. All objects of the same type will have the same type name. Type names can be used to test objects to see if they support the methods provided by a particular type before using them or to choose different code paths based upon the types of the objects at hand.

Lasso is dynamically typed, meaning that individual variables are not restricted to hold particular data types. However, Lasso does make use of type information in order to permit some variables to be type constrained and to allow different methods to be called based upon run-time type information through multiple-dispatch. See the chapter Defining Methods for more information.

Inheritance

Lasso supports the concept of single inheritance. This means that every type has one parent type. A type will inherit all of the data members and member methods of its parent. A type will combine the methods defined in its parent with the methods it defines in order to build upon the functionality provided by the parent.

If a method defined in a type conflicts with a method defined in its parent, then the method defined in the type will replace that of its parent. This is known as overriding the parent method.

Traits

Traits provide another means for extending types by allowing smaller units of functionality to be combined together and added to a type. A trait is similar to a type in that it contains member methods, but traits do not contain data members nor can they be created and used as objects.

A trait consists of zero or more methods which it provides and zero or more methods which it requires. In order for a type to take advantage of the methods which a trait provides, that type must implement the methods that the trait requires. This allows a trait to implement the mechanics of a feature by using the methods that it provides, while relying on the support of the methods it requires in order to perform some of the details.

Traits can also consist of zero or more sub-traits by combining multiple traits together. When traits are combined together they form a new trait which contains all of the provided and required methods from all of the sub-traits. In this manner, multiple traits, each providing an independent piece of functionality, work together to form a complete type.

Details of the syntax for creating traits and applying them to types is given in the chapter Defining Traits.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft