~sepisoad/vala-totrials/ValaTutorials

« back to all changes in this revision

Viewing changes to object_oriented/polymorphism/abstract.vala

  • Committer: Sepehr Aryani - (sepidev)
  • Date: 2010-12-10 20:45:38 UTC
  • Revision ID: sepehr.aryani@gmail.com-20101210204538-vqyr7d3cdbczo5wr
trivial changes...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2010  Sepehr Aryani
 
2
// Email: Sepehr.aryani@gmail.com
 
3
// Author : Sepehr Aryani (Sepidev)
 
4
 
 
5
/*
 
6
This file is part of Vala-Tutorials.
 
7
 
 
8
    Vala-Tutorials is free software: you can redistribute it and/or modify
 
9
    it under the terms of the GNU Lesser General Public License as published by
 
10
    the Free Software Foundation, either version 3 of the License, or
 
11
    any later version.
 
12
 
 
13
    Vala-Tutorials is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU Lesser General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU Lesser General Public License
 
19
    along with Vala-Tutorials.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
/**
 
23
 *      an abstract class that is acts as a base class
 
24
 */
 
25
 
 
26
public abstract class Animal : Object{
 
27
        
 
28
        /**
 
29
         * constructor
 
30
         */
 
31
        public Animal(){
 
32
                print("-> Animal\n");
 
33
        }
 
34
        
 
35
        /**
 
36
         * destructor
 
37
         */
 
38
        ~Animal(){
 
39
                print("<- Animal\n");
 
40
        }       
 
41
        
 
42
        /**
 
43
         * abstract function, has no implementaion yet.
 
44
         * can be overrided by subclasses.
 
45
         */
 
46
        public abstract void say_hello();
 
47
        
 
48
        /**
 
49
         * virtual function can be overrided by sub classes.
 
50
         */
 
51
        public virtual void say_bye(){
 
52
                print("bye...");
 
53
        }
 
54
}
 
55
 
 
56
public class Lion : Animal{
 
57
        
 
58
        /**
 
59
         * constructor
 
60
         */
 
61
        public Lion(){
 
62
                print("-> Lion\n");
 
63
        }       
 
64
        
 
65
        /**
 
66
         * destructor
 
67
         */
 
68
        ~Lion(){
 
69
                print("<- Lion\n");
 
70
        }
 
71
        
 
72
        /**
 
73
         * actual implementaion.
 
74
         */
 
75
        public override void say_hello(){
 
76
                print("hi, my name is Lion\n");
 
77
        }
 
78
        
 
79
        /**
 
80
         * overrided function.
 
81
         */
 
82
        public override void say_bye(){
 
83
                base.say_bye();
 
84
                print("HAAAAAAAAAAAAAAAA....\n");
 
85
        }
 
86
}
 
87
 
 
88
public class Eagle : Animal{
 
89
 
 
90
        /**
 
91
         * constructor
 
92
         */
 
93
        public Eagle(){
 
94
                print("-> Eagle\n");
 
95
        }       
 
96
        
 
97
        /**
 
98
         * destructor
 
99
         */
 
100
        ~Eagle(){
 
101
                print("<- Eagle\n");
 
102
        }
 
103
        
 
104
        /**
 
105
         * actual implementaion.
 
106
         */
 
107
        public override void say_hello(){
 
108
                print("hi, my name is Eagle\n");
 
109
        }
 
110
        
 
111
        /**
 
112
         * overrided function.
 
113
         */
 
114
        public override void say_bye(){
 
115
                print("GHAAAAAAAAAAAAAA....");
 
116
                base.say_bye();
 
117
                print("\n");
 
118
        }
 
119
}
 
120
 
 
121
public class Cow : Animal{
 
122
        
 
123
        /**
 
124
         * constructor
 
125
         */
 
126
        public Cow(){
 
127
                print("-> Cow\n");
 
128
        }       
 
129
        
 
130
        /**
 
131
         * destructor
 
132
         */
 
133
        ~Cow(){
 
134
                print("<- Cow\n");
 
135
        }
 
136
        
 
137
        /**
 
138
         * actual implementaion.
 
139
         */
 
140
        public override void say_hello(){
 
141
                print("hi, my name is Cow\n");
 
142
        }
 
143
        
 
144
        /**
 
145
         * overrided function.
 
146
         */
 
147
        public override void say_bye(){
 
148
                print("MOOOOOOOOOOOO....\n");
 
149
        }
 
150
}
 
151
 
 
152
public class Wolf : Animal{
 
153
 
 
154
        /**
 
155
         * constructor
 
156
         */
 
157
        public Wolf(){
 
158
                print("-> Wolf\n");
 
159
        }       
 
160
        
 
161
        /**
 
162
         * destructor
 
163
         */
 
164
        ~Wolf(){
 
165
                print("<- Wolf\n");
 
166
        }
 
167
        
 
168
        /**
 
169
         * actual implementaion.
 
170
         */
 
171
        public override void say_hello(){
 
172
                print("hi, my name is Wolf\n");
 
173
        }
 
174
        
 
175
        /**
 
176
         * overrided function.
 
177
         */
 
178
        public override void say_bye(){
 
179
                print("WHOOOOOOOOOOOOOOOO....\n");
 
180
        }
 
181
}