VSIP/formularium: verschil tussen versies

Uit Wina Examenwiki
Naar navigatie springen Naar zoeken springen
Regel 4: Regel 4:


  Object
  Object
subclass: #Room
        subclass: #Room
instanceVariableNames:'name maxpopulation currentPopulation visitors'
        instanceVariableNames:'name maxpopulation currentPopulation visitors'
classVariableNames: ''
        classVariableNames: ''
poolDictionaries: ''
        poolDictionaries: ''
  !
  !
  !Room class methodsFor: 'construction'!
  !Room class methodsFor: 'construction'!
  withName: theName andMaxPopulation: themaxpopulation
  withName: theName andMaxPopulation: themaxpopulation
|result|
        |result|
result := Room new.
        result := Room new.
result withName: theName andMaxPopulation: themaxpopulation.
        result withName: theName andMaxPopulation: themaxpopulation.
^result
        ^result
  !!
  !!
  !Room methodsFor: 'Initialization'!
  !Room methodsFor: 'Initialization'!
  withName: theName andMaxPopulation: themaxpopulation
  withName: theName andMaxPopulation: themaxpopulation
name := theName.
        name := theName.
maxpopulation := themaxpopulation.
        maxpopulation := themaxpopulation.
currentPopulation := 0.
        currentPopulation := 0.
visitors := Array new: maxpopulation.
        visitors := Array new: maxpopulation.
  !!
  !!



Versie van 15 dec 2008 12:49

Schrijf hier korte voorbeeldjes neer voor elke taal

Smalltalk

Object
       subclass: #Room
       instanceVariableNames:'name maxpopulation currentPopulation visitors'
       classVariableNames: 
       poolDictionaries: 	
!
!Room class methodsFor: 'construction'!
withName: theName andMaxPopulation: themaxpopulation
       |result|
       result := Room new.
       result withName: theName andMaxPopulation: themaxpopulation.
        ^result
!!
!Room methodsFor: 'Initialization'!
withName: theName andMaxPopulation: themaxpopulation
       name := theName.
       maxpopulation := themaxpopulation.
       currentPopulation := 0.
       visitors := Array new: maxpopulation.
!!

Eiffel

toewijzing :          :=
niet gelijk aan :     \=
null:                 Void  
string:               STRING
int:                  INTEGER     
this:                 Current  
return value:         Result
if cond then C1 else C2 end
class
  NEWCLASS                            -- de naam van je klasse
creation
  constructormethod                   -- constructoren aanduiden
feature{}                             -- globale variabelen      
  name:STRING
feature{}                             -- private other: feature{ANY}, feature{NAMECLASS1,NAMECLASS2}
  constructormethod(newname: like name) is       
  do                                  -- start method
     name :=  newname                 -- do stuff
  end                                 -- end constructor
feature{ANY}    
   get_name :STRING is                 -- get_name method (NAMING CONVENTIONS: get_name)
      do                               --start method
           Result := name              --return name
      end                              --end method    
invariant
   valid_name : not Current.name.is_equal("")
end                                   -- end class NEWCLASS

overerving voorbeeld

class
       AUDITORIUM
inherit
       ROOM	
            rename build as build_room end  -- redefine parent method
creation
        build
feature{}
        build(n: like name; p: INTEGER) is -- (arg :like var) or (arg : TYPE) 
        do
               build_room(n, p) -- constructor parent classe aanroepe		
       end
end

C++

C#

Getters en setters:

  • Mogelijkheid 1
private string foo;
public string Foo {
  get { return foo; }
  set { foo = value; }
}
  • Mogelijkheid 2 (indien zowel getter en setter publiek) (C# 3.0+)
public string Foo { get; set; }