jeudi 20 janvier 2022

Interface in an array

Hye everyone, Do you know if it is good practice to make a table with an interface like this? :

 public interface ITemp
 {
    void Findpath();
 }

 public class TempUn : ITemp
 {
    public void Findpath()
    {
          throw new System.NotImplementedException();
    }
 }

 public class TempDeux : ITemp
 {
     public int deux;
     public void Findpath()
     {
          throw new System.NotImplementedException();
     }
 }

 public ITemp[] TabTest;

 public void init()
 {
     var un = new TempUn();
     var deux = new TempDeux();

     TabEssai = new ITemp[2];
        TabEssai[0] = un;
        TabEssai[1] = deux;
 }

I'm asking this because if I understand correctly the creation of the array allocates a fixed memory. I'm not sure if it's a good idea to create an array of elements that respect the interface but are of variable size, , is that a problem?

Good Day,

Aucun commentaire:

Enregistrer un commentaire