Permalink
Browse files

Subindo definição de herança para animal e dog

  • Loading branch information...
danielhba committed Oct 3, 2012
1 parent 94833a7 commit 21dd47f6d71f8ef3100afa4497d9aa3224902949
@@ -5,53 +5,11 @@ class method.
main() ->
- Fab1 = Fabricante::new("Nike", {08, 2012}),
- Bola1 = Bola::new("Azul", "12", "Borracha", Fab1),
+ Dog = Dog::new("Milu", "White", 7),
- Fab2 = Fabricante::new("Adidas", {09, 2011}),
- Bola2 = Bola::new("Vermelha", "7", "Plástico", Fab2),
+ Animal = Animal::new("Tom", "Gray", 5),
- Cor1 = Bola1::get_cor(),
- Cor2 = Bola2::get_cor(),
+ Dog::bark(),
+ Dog::print(),
- io:format("~p~n", [Cor1]),
- io:format("~p~n", [Cor2]),
-
- Bola1::set_cor("Amarela"),
- Bola2::set_cor("Preta"),
-
- Cor3 = Bola1::get_cor(),
- Cor4 = Bola2::get_cor(),
-
- io:format("~p~n", [Cor3]),
- io:format("~p~n", [Cor4]),
-
- F1_nome = Fab1::get_nome(),
- F2_nome = Fab2::get_nome(),
-
- io:format("~p~n", [F1_nome]),
- io:format("~p~n", [F2_nome]),
-
- F1_nome = Fab1:get_nome(Fab1_key),
- F2_nome = Fab2:get_nome(Fab2_key),
-
- io:format("~p~n", [F1_nome]),
- io:format("~p~n", [F2_nome]),
-
- Fab1_data = Bola1::get_fabricante_data_fabricacao(),
- Fab2_data = Bola2::get_fabricante_data_fabricacao(),
-
- io:format("~p~n", [Fab1_data]),
- io:format("~p~n", [Fab2_daa]),
-
- Bola1::set_fabricante_nome("Topper"),
- Bola2::set_fabricante_nome("Umbro"),
-
- Fab3_nome = Bola1::get_fabricante_nome(),
- Fab4_nome = Bola2::get_fabricante_nome(),
-
- io:format("~p~n", [Fab3_nome]),
- io:format("~p~n", [Fab4_nome]),
-
- Fab5_nome = Bola1::fabricante::get_nome(),
- io:format("~p~n", [Fab4_nome]).
+ Animal::print().
@@ -1,30 +0,0 @@
-Herança
-
--class( animmal ).
--constructor(new/3).
--exports([print/0]).
-
-class_attributes.
-
-Name
-Color
-Age
-
-class_methods.
-
-new( N, C, A ) ->
- self::Name = N,
- self::Color = C,
- self::Age = A.
-
-print() ->
- io:format("I'm ~d~n",self::Name).
-
-
-
--class( dog ).
--extends( mammal ).
--exports([bark/0]).
-
-class_methods.
- bark()->io:format("Woof! Woof!").
@@ -0,0 +1,19 @@
+-class(Animmal).
+-constructor(new/3).
+-exports([print/0]).
+
+class_attributes.
+
+name
+color
+age
+
+class_methods.
+
+new( N, C, A ) ->
+ self::name = N,
+ self::color = C,
+ self::age = A.
+
+print() ->
+ io:format("I'm ~p~n", [self::name]).
@@ -0,0 +1,22 @@
+-module(animal, [Name, Color, Age]).
+-export([constructor/0, print/1]).
+
+constructor() ->
+ Key = key(),
+ put({animal, name, Key}, Name),
+ put({animal, color, Key}, Color),
+ put({animal, age, Key}, Age),
+ Key.
+
+print(Key) ->
+ io:format("I'm ~p~n", [get({animal, name, Key})]).
+
+key() ->
+ case get({animal, key}) of
+ undefined ->
+ put({animal, key}, 0),
+ 0;
+ Key ->
+ put({animal, key}, Key + 1),
+ Key + 1
+ end.
@@ -0,0 +1,8 @@
+-class(Dog).
+-extends(Animal).
+-exports([bark/0]).
+
+class_methods.
+
+bark()->
+ io:format("Woof! Woof!~n").
View
@@ -0,0 +1,25 @@
+-module(dog, [Name, Color, Age]).
+-export([constructor/0, print/1, bark/1]).
+
+constructor() ->
+ Key = key(),
+ put({dog, name, Key}, Name),
+ put({dog, color, Key}, Color),
+ put({dog, age, Key}, Age),
+ Key.
+
+print(Key) ->
+ io:format("I'm ~p~n", [get({dog, name, Key})]).
+
+bark(Key)->
+ io:format("Woof! Woof!~n").
+
+key() ->
+ case get({dog, key}) of
+ undefined ->
+ put({dog, key}, 0),
+ 0;
+ Key ->
+ put({dog, key}, Key + 1),
+ Key + 1
+ end.
@@ -0,0 +1,15 @@
+-class(Principal).
+-export([main/0]).
+
+class method.
+
+main() ->
+
+ Dog = Dog::new("Milu", "White", 7),
+
+ Animal = Animal::new("Tom", "Gray", 5),
+
+ Dog:bark(),
+ Dog:print(),
+
+ Animal:print().
@@ -0,0 +1,35 @@
+-module(principal, []).
+-export([constructor/0, start/0, main/0]).
+
+constructor() ->
+ Key = key(),
+ Key.
+
+start() ->
+ spawn(fun() -> main() end).
+
+main() ->
+ receive
+ start -> ok
+ end,
+
+ Dog = dog:new("Milu", "White", 7),
+ Dog_key = Dog:constructor(),
+
+ Animal = animal:new("Tom", "Gray", 5),
+ Animal_key = Animal:constructor(),
+
+ Dog:bark(Dog_key),
+ Dog:print(Dog_key),
+
+ Animal:print(Animal_key).
+
+key() ->
+ case get({principal, key}) of
+ undefined ->
+ put({principal, key}, 0),
+ 0;
+ Key ->
+ put({principal, key}, Key + 1),
+ Key + 1
+ end.
View
@@ -0,0 +1,13 @@
+-module(run).
+-export([run/0]).
+
+run() ->
+ compile:file("principal.erl"),
+ compile:file("animal.erl"),
+ compile:file("dog.erl"),
+
+ M = principal:new(),
+ M_Key = M:constructor(),
+
+ P = M:start(),
+ P ! start.

0 comments on commit 21dd47f

Please sign in to comment.