Message-ID: <108505528.4703.1419171998035.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4702_1820390791.1419171998034" ------=_Part_4702_1820390791.1419171998034 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
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. <=
fields hold information and
are accessors to that information.
class Cat:declares the start of a
propertyaround <= code>_name. You named the
_name as stringdeclares a
Cat=that is a
fluffy =3D Cat()declares an instance of
fluffy.Name =3D 'Fluffy'accesses the
Catand sets its value to
'Fluffy= '. This will cause
Fields are not set directly because of security.=20 =20
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
setter statement, that contains the value to =
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>=20
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.
abstract keyword is the Class Modifier.
Inheritance is very simple in Boo.=20 =20
Cat to inherit from
Feline. This g=
ives the members
/code>, even though they were not declared in
You can also have more than one
class inherit from the same =
class, which promotes code reuse.
More about inheritance is covered in Part 10 - Polymorphism, or Inherited M= ethods=20
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
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.
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.=20 =20
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