Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2472 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [c#] objets -- peut être une question de noob

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[c#] objets -- peut être une question de noob

n°1725201
bill_clint​on
nonon j'ai pas de stagiaire ..
Posté le 27-04-2008 à 18:42:16  profilanswer
 

salut !
 
   Alors, d'habitude en poo je met tout dans un objet, propriétés et fonctions pour ses actions (delete, update, add par exemple)
   Cette semaine au boulot quelqu'un a profité du fait que je sois en congé pour refaire tout le départ d'une appli, il a viré toutes les fonctions
   des objets sous prétexte que ça prenait trop de place et les a mis à coté, résultat les objets n'ont plus que le propriétés et c'est le bordel
   de partout pour faire un objet il faut passer par 4 classes maintenant ;)
 
   Mais pas de soucis, billou est là et je teste donc ça aujourd'hui ;)
 
   alors 2 objets avec les mêmes propriétés, un sans fonctions et un avec :
 
 

Code :
  1. public class ObjectFunctions
  2. {
  3.   #region "Propriétés privées"
  4.   // *********************************************************************************************************
  5.   // ****************************************** Propriétés privées *******************************************
  6.   private string mProperty1;
  7.   private string mProperty2;
  8.   private string mProperty3;
  9.   private string mProperty4;
  10.   private string mProperty5;
  11.   private string mProperty6;
  12.   private string mProperty7;
  13.   private string mProperty8;
  14.   private string mProperty9;
  15.   private string mProperty10;
  16.   // *************************************** Fin de propriétés privées ***************************************
  17.   // *********************************************************************************************************
  18.   #endregion
  19.   #region "Propriétés publiques"
  20.   // *********************************************************************************************************
  21.   // ***************************************** Propriétés publiques ******************************************
  22.   public string Property1
  23.   {get {return mProperty1;}
  24.    set {mProperty1 = value;}}
  25.   public string Property2
  26.   {get {return mProperty2;}
  27.    set {mProperty2 = value;}}
  28.   public string Property3
  29.   {get {return mProperty3;}
  30.    set {mProperty3 = value;}}
  31.  
  32.   public string Property4
  33.   {get {return mProperty4;}
  34.    set {mProperty4 = value;}}
  35.  
  36.   public string Property5
  37.   {get {return mProperty5;}
  38.    set {mProperty5 = value;}}
  39.  
  40.   public string Property6
  41.   {get {return mProperty6;}
  42.    set {mProperty6 = value;}}
  43.  
  44.   public string Property7
  45.   {get {return mProperty7;}
  46.    set {mProperty7 = value;}}
  47.  
  48.   public string Property8
  49.   {get {return mProperty8;}
  50.    set {mProperty8 = value;}}
  51.  
  52.   public string Property9
  53.   {get {return mProperty9;}
  54.    set {mProperty9 = value;}}
  55.  
  56.   public string Property10
  57.   {get {return mProperty10;}
  58.    set {mProperty10 = value;}}
  59.   // ************************************** Fin de propriétés publiques **************************************
  60.   // *********************************************************************************************************
  61.   #endregion
  62.  
  63.   public ObjectFunctions()
  64.   {
  65.   }
  66.   public ObjectFunctions(System.Int32 _record_id)
  67.   {mProperty1 = "Property1_" + _record_id.ToString();
  68.    mProperty2 = "Property2_" + _record_id.ToString();
  69.    mProperty3 = "Property3_" + _record_id.ToString();
  70.    mProperty4 = "Property4_" + _record_id.ToString();
  71.    mProperty5 = "Property5_" + _record_id.ToString();
  72.    mProperty6 = "Property6_" + _record_id.ToString();
  73.    mProperty7 = "Property7_" + _record_id.ToString();
  74.    mProperty8 = "Property8_" + _record_id.ToString();
  75.    mProperty9 = "Property9_" + _record_id.ToString();
  76.    mProperty10 = "Property10_" + _record_id.ToString();}
  77.   public string GetProperties()
  78.   {string _buf = mProperty1 + " et " + mProperty2 + " et " + mProperty3 + " et " + mProperty4 + " et " +
  79.             mProperty5 + " et " + mProperty6 + " et " + mProperty7 + " et " + mProperty8 + " et " +
  80.             mProperty9 + " et " + mProperty10;
  81.    return _buf;}
  82.   public string GetPropertiesOther()
  83.   {string _buf = mProperty1 + " plus " + mProperty2 + " plus " + mProperty3 + " plus " + mProperty4 + " plus " +
  84.             mProperty5 + " plus " + mProperty6 + " plus " + mProperty7 + " plus " + mProperty8 + " plus " +
  85.             mProperty9 + " plus " + mProperty10;
  86.    return _buf;}
  87.   public string GetPropertiesOther1()
  88.   {string _buf = mProperty1 + " plus " + mProperty2 + " plus " + mProperty3 + " plus " + mProperty4 + " plus " +
  89.             mProperty5 + " plus " + mProperty6 + " plus " + mProperty7 + " plus " + mProperty8 + " plus " +
  90.             mProperty9 + " plus " + mProperty10;
  91.    return _buf;}
  92.   public string GetPropertiesOther2()
  93.   {string _buf1 = mProperty1 + " plus " + mProperty2 + " plus " + mProperty3 + " plus " + mProperty4 + " plus " +
  94.     mProperty5;
  95.    string _buf2 = " plus " + mProperty6 + " plus " + mProperty7 + " plus " + mProperty8 + " plus " +
  96.     mProperty9 + " plus " + mProperty10;
  97.    return _buf1 + _buf2;}
  98. }
  99. [cpp]
  100. [cpp]
  101.   public class ObjectNoFunctions
  102.   {
  103.   #region "Propriétés privées"
  104.   // *********************************************************************************************************
  105.   // ****************************************** Propriétés privées *******************************************
  106.   private string mProperty1;
  107.   private string mProperty2;
  108.   private string mProperty3;
  109.   private string mProperty4;
  110.   private string mProperty5;
  111.   private string mProperty6;
  112.   private string mProperty7;
  113.   private string mProperty8;
  114.   private string mProperty9;
  115.   private string mProperty10;
  116.   // *************************************** Fin de propriétés privées ***************************************
  117.   // *********************************************************************************************************
  118.   #endregion
  119.   #region "Propriétés publiques"
  120.   // *********************************************************************************************************
  121.   // ***************************************** Propriétés publiques ******************************************
  122.   public string Property1
  123.   {get {return mProperty1;}
  124.    set {mProperty1 = value;}}
  125.   public string Property2
  126.   {get {return mProperty2;}
  127.    set {mProperty2 = value;}}
  128.   public string Property3
  129.   {get {return mProperty3;}
  130.    set {mProperty3 = value;}}
  131.  
  132.   public string Property4
  133.   {get {return mProperty4;}
  134.    set {mProperty4 = value;}}
  135.  
  136.   public string Property5
  137.   {get {return mProperty5;}
  138.    set {mProperty5 = value;}}
  139.  
  140.   public string Property6
  141.   {get {return mProperty6;}
  142.    set {mProperty6 = value;}}
  143.  
  144.   public string Property7
  145.   {get {return mProperty7;}
  146.    set {mProperty7 = value;}}
  147.  
  148.   public string Property8
  149.   {get {return mProperty8;}
  150.    set {mProperty8 = value;}}
  151.  
  152.   public string Property9
  153.   {get {return mProperty9;}
  154.    set {mProperty9 = value;}}
  155.  
  156.   public string Property10
  157.   {get {return mProperty10;}
  158.    set {mProperty10 = value;}}
  159.   // ************************************** Fin de propriétés publiques **************************************
  160.   // *********************************************************************************************************
  161.   #endregion
  162.  
  163.   public ObjectNoFunctions()
  164.   {}
  165. }


 
 
 ensuite je les appelle dans une fenêtre :
 
 

Code :
  1. private void btn_PopulateObjectFunctions_Click(object sender, System.EventArgs e)
  2.   {
  3.    ArrayList _objectFunctionsLists = new ArrayList();
  4.    ObjectFunctions _objectFunctions;
  5.    for (Int32 i = 0; i < 600000; i++)
  6.    {_objectFunctions = new ObjectFunctions(i);
  7.     _objectFunctionsLists.Add(_objectFunctions);}
  8.    MessageBox.Show("Terminé" );
  9.   }
  10.   private void btn_PopulateObjectNoFunctions_Click(object sender, System.EventArgs e)
  11.   {
  12.    ArrayList _objectNoFunctionsLists = new ArrayList();
  13.    ObjectNoFunctions _objectNoFunctions;
  14.    for (Int32 i = 0; i < 600000; i++)
  15.    {_objectNoFunctions = new ObjectNoFunctions();
  16.     _objectNoFunctions.Property1 = "Property1_" + i.ToString();
  17.     _objectNoFunctions.Property2 = "Property2_" + i.ToString();
  18.     _objectNoFunctions.Property3 = "Property3_" + i.ToString();
  19.     _objectNoFunctions.Property4 = "Property4_" + i.ToString();
  20.     _objectNoFunctions.Property5 = "Property5_" + i.ToString();
  21.     _objectNoFunctions.Property6 = "Property6_" + i.ToString();
  22.     _objectNoFunctions.Property7 = "Property7_" + i.ToString();
  23.     _objectNoFunctions.Property8 = "Property8_" + i.ToString();
  24.     _objectNoFunctions.Property9 = "Property9_" + i.ToString();
  25.     _objectNoFunctions.Property10 = "Property10_" + i.ToString();
  26.    
  27.     _objectNoFunctionsLists.Add(_objectNoFunctions);}
  28.    MessageBox.Show("Terminé" );
  29.   }


 
 
 la mémoire utilisée ne varie pas d'un chouia entre les deux boutons
 
 quand on fait ça, la fonction de l'objet se retrouve en mémoire pour chaque objet ou alors c'est simplement un référence ? (à priori ca devrait l'être)

mood
Publicité
Posté le 27-04-2008 à 18:42:16  profilanswer
 

n°1727038
MagicBuzz
Posté le 30-04-2008 à 18:06:38  profilanswer
 

J'ai pas lu en détail, donc je risque de répondre plus ou moins à côté de la plaque.
 
En gros, si tu as un objet A et que tu crée un second objet B qui prend la valeur de A, alors B est une référence vers A.
 
Si tu détruit A (a = null), par contre, il est entièrement recopié dans B.
 
Je t'invite à lire la doc de la MSDN sur le sujet (cherche "ref" et "value types" dans la doc, tu devrais trouver des liens expliquant les différences de fonctionnement entre les types de valeur et de référence).

n°1727468
bill_clint​on
nonon j'ai pas de stagiaire ..
Posté le 02-05-2008 à 01:17:31  profilanswer
 

hehe c'était pas ca ;)
 
c'était "les méthodes d'un objet n'ont visiblement pas l'air d'être contenues dans l'objet instancié mais seulement dans la définition"


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [c#] objets -- peut être une question de noob

 

Sujets relatifs
Question Xsl / Xpathsauvegarde et chargement d'un tableau d'objets (class)
Question RecordSetPetite question rapide
Question de gros débutantBDD et les objets graphique
Question de design : WebServices et rétrocompatibilitéRequête SQL - Question plutôt simple :p
[VBA] Petite question pour bouton sur Excelquestion
Plus de sujets relatifs à : [c#] objets -- peut être une question de noob


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR