background preloader

Objets

Facebook Twitter

La Programmation Orientée Objet en Perl. La POO est une méthode de programmation née de réflexions sur la qualité et le coût de la création et de l'entretien d'un programme. En effet, il a été constaté que de 70 à 80% du coût d'un programme provient de la phase de maintenance et non de celle de création pure. Le but de la POO est de réduire ce coût. Pour cela, on a fixé des critères de qualité d'un programme OO. Ils sont au nombre de quatre : la Validité : respect du cahier des charges ; l'Extensibilité : permettre l'ajout de fonctionnalités ; la Réutilisabilité : permettre l'utilisation d'un même composant pour différentes applications ; la Robustesse : consiste en un traitement des exceptions.

À la vue de ceci, vous vous demandez pourquoi apprendre la POO : il y a de fortes chances que vous n'ayez pas à programmer un jour une application d'un coût élevé, donc pourquoi l'utiliser ? Sans trop détailler, je vais essayer d'établir la philosophie de base de la POO. Maintenant, prenons deux personnes différentes. 2-A. 2-B. 2-C.

Jouons avec Moose (ou comment réapprendre le Perl Objet) – partie 1 | Sukria.net. Object Oriented Programming in PERL. Before we start Object Oriented concept of perl, lets understand references and anonymous arrays and hashes References A reference is, exactly as the name suggests, a reference or pointer to another object. There are two types of references: symbolic and hard. A symbolic reference enables you to refer to a variable by name, using the value of another variable. For example, if the variable $foo contains the string "bar", the symbolic reference to $foo refers to the variable $bar. A hard reference refers to the actual data contained in a data structure. Creating Hard References The unary backslash operator is used to create a reference to a named variable or subroutine, for example: $foo = 'Bill'; $fooref = \$foo; The $fooref variable now contains a hard reference to the $foo variable.

$array = \@ARGV; $hash = \%ENV; $glob = \*STDOUT; To create a reference to a subroutine: sub foo { print "foo" }; $foosub = \&foo; Anonymous Arrays Creating an anonymous array is easy: $array = [ 'Bill', 'Ben, 'Mary' ]; Perl Object Oriented Programming. Download source files - 1.7 Kb Camel POOP Most people are not aware of the fact that Perl has support for object-oriented programming.

If you've used another object-oriented programming language such as Java or C++ or been exposed to object-orientation, then object oriented programming in Perl is nothing like that. To do real useful object-oriented programming in Perl, you only need to use three simple rules as put forth by Larry Wall in Object Oriented Perl. Object oriented programmers are familiar with the concept of object and classes, but I will review that here quickly. An example would be a Person class in an HR system. Package delivery To create a class in Perl, we first build a package. To declare a class named Person in Perl we do: package Person; That's it.

There's a method to this madness A method is a means by which an object's data is accessed or modified. The subroutine print is now associated with the package Person. $khurt->print(); How do we create the invoking object? $ . Objects in Perl.