Thread Perl 5.x: Gute Beispiele zum Lernen von MVC (Theorie+Praxis) (3 answers)
Opened by GwenDragon at 2021-04-20 18:27

hlubenow
 2021-04-26 02:32
#193246 #193246
User since
2009-02-22
875 Artikel
BenutzerIn
[default_avatar]
Hier gerade mal ein minimales Code-Beispiel:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl

use warnings;
use strict;

package Model {

    sub new {
        my $classname = shift;
        my $self = { controller => shift};
        return bless($self, $classname);
    }

    sub calculateThreePlusFour {
        my $self = shift;
        return 3 + 4;
    }
}

package View {

    sub new {
        my $classname = shift;
        my $self = { controller => shift};
        return bless($self, $classname);
    }

    sub showResult {
        my $self = shift;
        my $result = shift;
        print "$result\n";
    }
}

package Controller {

    sub new {
        my $classname = shift;
        my $self = {};
        $self->{model} = Model->new($self);
        $self->{view} = View->new($self);
        return bless($self, $classname);
    }

    sub run {
        my $self = shift;
        my $result = $self->{model}->calculateThreePlusFour();
        $self->{view}->showResult($result);
    }

}

my $controller = Controller->new();
$controller->run();


Edit: Wie gesagt, so mache ich das. Ob man das in der Industrie auch so macht, weiß ich leider nicht. Würde mich aber freuen, wenn jemand was dazu sagen könnte.
Last edited: 2021-04-26 02:35:36 +0200 (CEST)

View full thread Perl 5.x: Gute Beispiele zum Lernen von MVC (Theorie+Praxis)