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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
*********un premier fichier, Employe
public class Employe{ //eventuellement abstract
String nom;
//autre variable commune à tous les employés (adresse etc...)
public Employe(String nom){
this.nom=nom;
//autre truc à faire
}
public void uneMethodeCommuneaTousLesEmployes(){
//faire un truc commun à tous les employés
}
}
***********Autre fichier EmployeHoraire
public Class EmployeHoraire extends Employe{
public int nombreDHeure;
//autres variables particulières à un employé horaire
public EmployeHoraire(String nom,int nbH){
super(nom);
nombreDHeure=bbH;
//autre choses particulières à un employé horaire
}
public void uneMethodePourlesEmployeHoraire(){
//faire un truc spécifique au employés horaires
}
}
************Autre fichier EmployeCommercial
public Class EmployeCommercial extends Employe{
public float pourcentage;
//autres variables particulières à un employé commercial
public EmployeCommercial(String nom,float perc){
super(nom);
pourcentage=perc;
//autre choses particulières à un employé commercial
}
public void uneMethodePourlesEmployeCommercial(){
//faire un truc spécifique aux commerciaux
}
}
***************Fichier pour utiliser
//déclaration
Employe[] employes = new Employe[5];
employes[0]=new EmployeHoraire("Poiret", 42);
employes[1]=new EmployeHoraire("Burot", 30);
employes[2]=new EmployeCommercial("Dupont", 7.5);
employes[3]=new EmployeCommercial("Ravier", 8.4);
employes[4]=new EmployeHoraire("Terrice",20);
...
//utilisation
for (int i=0;i<employes.length;i++){
if employes[i].instanceof(EmployeCommercial.class){
//faire le traitement ad-hoc
}
} |