Message-ID: <453767145.42342.1371713800139.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_42341_69918922.1371713800138" ------=_Part_42341_69918922.1371713800138 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
A cohesive package that consists of a particular kind of compile-time me= tadata. A class describes the rules by which objects behave. A class specif= ies the structure of data which each instance contains as well as the metho= ds (functions) which manipulate the data of the object.
An instance of a class
Classes are important because they allow you to split up yo=
ur code into simpler, logical parts. They also allow for better organizatio=
n and data manipulation.
This declares a blank
"Cat". It can't do anything at all, because there's nothing to do with it. <=
Name all your
An element in a
A syntax nicety to use instead of getter/setter functions.
fields hold information and
are accessors to that information.
class Cat:declares the start of a
_name. You named the
_name as stringdeclares a
fluffy =3D Cat()declares an instance of
fluffy.Name =3D 'Fluffy'accesses the
Catand sets its value to
'Flu= ffy'. This will cause
Fields are not set directly because of security.
Name all your
There are two other types of
getter and a
setter. Technically, a regular
is just the combination of the two.
If you were to try to assign a value to
fluffy.Name or retr=
ieve a value from
fluffy.FavoriteFood, an error would have occ=
urred, because the code just does not exist for you to do that.
Setter are very handy, but it's actually Boo's short=
ened version of what is really happening. Here's an example of the full cod=
fields are visible inside their own class, you can =
Name is just a wrapper around
ng this expanded syntax is handy if you want to do extra verification or no=
t have it wrap exactly around its
field, maybe by trimming whi=
tespace or something like that first.
value is a special keyword for the
nt, that contains the value to be assigned.
It is also possible to define a precondition that must be met before set= ting a value directly through the Property shorthand.
Creates a normal, public class, fully access= ible to all other types.
Creates a class that is only accessible by i= ts containing class (the class this was declared in) and any inheriting cla= sses.
A class only accessible by the assembly it w= as declared in.
Combination of protected and internal.<= /td>
Creates a class that is only accessible by i= ts containing class (the class this was declared in.)
Creates a class that cannot be instanced. Th= is is designed to be a base class for others.
Creates a class that cannot be inherited fro= m.
Never use the
abstract keyword is the Class Modifier.
A way to form new classes (instances of which will be objects) using pre= -defined objects or classes where new ones simply take over old ones's impl= emetions and characterstics. It is intended to help reuse of existing code = with little or no modification.
Inheritance is very simple in Boo.
Cat to inherit from
Feline. This g=
ives the members
/code>, even though they were not declared in , which promotes code reuse.
You can also have more than one
class inherit from the same
More about inheritance is covered in Part 10 - Polymorphism, or Inherited M= ethods
Classes can inherit from one or zero other
classes and any number of
To inherit from more than one interface, you would use the notation
An interface defines a list of methods that enables a class to implement= the interface itself.
Interfaces allow you to set up an API (Application Programm=
ing Interface) for
classes to base themselves off of.
No implementation of code is put inside
interfaces, that is=
up to the
Interfaces can inherit from any number of other
faces. They cannot inherit from any
This defines IFeline having one method, Roar, and one
Properties must be explicitly declared in
erfaces. Methods are explained in Part 09 - Methods.
Name your interfaces using PascalCase prefixed with the letter I, such a= s IFeline.
There are two types in the Boo/.NET world: Value and Reference types. Al= l classes form Reference types. Numbers and such as was discussed in Pa= rt 02 - Variables#List of Value Types are value types.
A keyword used to specify an undefined value for reference variables.
Value types can never be set to
null, they will always have=
a default value. Numbers default value will generally be 0.
classthat inherits from more than one
Go on to Part 09 - Me= thods------=_Part_42341_69918922.1371713800138--