Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,14 +1,28 @@
In [[object-oriented programming]] '''class''' is a set (a [[wp:Transitive_closure|transitive closure]]) of types bound by the relation of [[inheritance]]. It is said that all types derived from some base type T and the type T itself form a class T. The first type T from the class T sometimes is called the '''root type''' of the class.
In [[object-oriented programming]] '''class''' is a set (a [[wp:Transitive_closure|transitive closure]]) of types bound by the relation of [[inheritance]]. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the '''root type''' of the class.
A class of types itself, as a type, has the values and operations of its own. The operations of are usually called '''methods''' of the root type. Both operations and values are called [[polymorphism | polymorphic]].
A class of types itself, as a type, has the values and operations of its own.
The operations of are usually called '''methods''' of the root type.
Both operations and values are called [[polymorphism | polymorphic]].
A polymorphic operation (method) selects an implementation depending on the actual specific type of the polymorphic argument. The action of choice the type-specific implementation of a polymorphic operation is called '''dispatch'''. Correspondingly, polymorphic operations are often called '''dispatching''' or '''virtual'''. Operations with multiple arguments and/or the results of the class are called '''multi-methods'''. A further generalization of is the operation with arguments and/or results from different classes.
A polymorphic operation (method) selects an implementation depending on the actual specific type of the polymorphic argument.
The action of choice the type-specific implementation of a polymorphic operation is called '''dispatch'''. Correspondingly, polymorphic operations are often called '''dispatching''' or '''virtual'''.
Operations with multiple arguments and/or the results of the class are called '''multi-methods'''.
A further generalization of is the operation with arguments and/or results from different classes.
* single-dispatch languages are those that allow only one argument or result to control the dispatch. Usually it is the first parameter, often hidden, so that a prefix notation ''x''.''f''() is used instead of mathematical ''f''(''x'').
* multiple-dispatch languages allow many arguments and/or results to control the dispatch.
A polymorphic value has a type tag indicating its specific type from the class and the corresponding specific value of that type. This type is sometimes called '''the most specific type''' of a [polymorphic] value. The type tag of the value is used in order to resolve the dispatch. The set of polymorphic values of a class is a transitive closure of the sets of values of all types from that class.
A polymorphic value has a type tag indicating its specific type from the class and the corresponding specific value of that type.
This type is sometimes called '''the most specific type''' of a [polymorphic] value.
The type tag of the value is used in order to resolve the dispatch.
The set of polymorphic values of a class is a transitive closure of the sets of values of all types from that class.
In many [[object-oriented programming | OO]] languages the type of the class of T and T itself are considered equivalent. In some languages they are distinct (like in [[Ada]]). When class T and T are equivalent, there is no way to distinguish polymorphic and specific values.
In many [[object-oriented programming | OO]] languages
the type of the class of T and T itself are considered equivalent.
In some languages they are distinct (like in [[Ada]]).
When class T and T are equivalent, there is no way to distinguish
polymorphic and specific values.
The purpose of this task is to create a basic class with a method, a constructor, an instance variable and how to instantiate it.
The purpose of this task is to create a basic class with a method,
a constructor, an instance variable and how to instantiate it.

View file

@ -0,0 +1,9 @@
; You can think of this as an interface
(defprotocol Foo (getFoo [this]))
; Generates Example1 Class with foo as field, with method that returns foo.
(defrecord Example1 [foo] Foo (getFoo [this] foo))
; Create instance and invoke our method to return field value
(-> (Example1. "Hi") .getFoo)
"Hi"

View file

@ -1,4 +1,4 @@
public class MyClass {
public class MyClass{
// instance variable
private int variable; // Note: instance variables are usually "private"
@ -6,14 +6,14 @@ public class MyClass {
/**
* The constructor
*/
public MyClass() {
public MyClass(){
// creates a new instance
}
/**
* A method
*/
public void someMethod() {
public void someMethod(){
this.variable = 1;
}
}

View file

@ -0,0 +1 @@
new MyClass();

View file

@ -1,10 +1,11 @@
@implementation MyClass
// Was not declared because init is defined in NSObject
- (id)init
- (instancetype)init
{
if (self = [super init])
variable = 0;
if (self = [super init]) {
variable = 0; // not strictly necessary as all instance variables are initialized to zero
}
return self;
}

View file

@ -0,0 +1,14 @@
Class NumberContainer
Private TheNumber As Integer
Sub Constructor(InitialNumber As Integer)
TheNumber = InitialNumber
End Sub
Function Number() As Integer
Return TheNumber
End Function
Sub Number(Assigns NewNumber As Integer)
TheNumber = NewNumber
End Sub
End Class

View file

@ -0,0 +1,2 @@
Dim num As New NumberContainer(1) ' call the constructor
num.Number = num.Number + 5 ' call both Number methods

View file

@ -1,26 +1,13 @@
class MyClass
@@class_var = []
def initialize
# 'initialize' is the constructor method invoked during 'MyClass.new'
@instance_var = 0
end
def some_method
@instance_var = 1
@@class_var << Time.now
def add_1
@instance_var += 1
end
def self.class_method
# ...
end
# another way to define class methods: define an instance method in this class object's singleton class
class << self
def another_class_method
# ...
end
end
end
myclass = MyClass.new
my_class = MyClass.new #allocates an object and calls it's initialize method, then returns it.

View file

@ -0,0 +1,19 @@
typeset -T Summation_t=(
integer sum
# the constructor
function create {
_.sum=0
}
# a method
function add {
(( _.sum += $1 ))
}
)
Summation_t s
for i in 1 2 3 4 5; do
s.add $i
done
print ${s.sum}