¿Un return o varios?

La cosa no está clara:

https://stackoverflow.com/questions/36707/should-a-function-have-only-one-return-statement

Artículo sobre el tema:

https://www.anthonysteele.co.uk/TheSingleReturnLaw

Una buena práctica:

Minimize the number of returns in each routine. It’s harder to understand a routine if, reading it at the bottom, you’re unaware of the possibility that it returned somewhere above.

Use a return when it enhances readability. In certain routines, once you know the answer, you want to return it to the calling routine immediately. If the routine is defined in such a way that it doesn’t require any cleanup, not returning immediately means that you have to write more code.

Escribir en fichero


string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, "salida.txt")));
outputFile.WriteLine("Esto es una línea");
outputFile.WriteLine("Esto es otra");
outputFile.Close();

Inyección de dependencia

Las interfaces nos permiten desacoplar las funciones al no depender de una clase, sino de la implementación de un interfaz:

https://anexsoft.com/ejemplo-de-inyeccion-de-dependencias-con-c

Definición:

https://www.freecodecamp.org/news/a-quick-intro-to-dependency-injection-what-it-is-and-when-to-use-it-7578c84fa88f/

https://www.dotnettricks.com/learn/dependencyinjection/implementation-of-dependency-injection-pattern-in-csharp

Gente que está en contra (en ocasiones):

Las ventajas de NO usar inyección de dependencias

Ejercicio herencia

Arreglar la siguiente jerarquía de herencias para que incorpore constructores en las clases derivadas y funcione el área:

abstract class Figuras {
    abstract function area();  
}
abstract class Bidimensional extends Figuras{
    
}
class Circulo extends Bidimensional{
    private $radio;
}
class Triangulo extends Bidimensional{
  private $base;
  private $altura;
}
abstract class Tridimensional extends Figuras{
    
}
class Cubo extends Tridimensional{
   private $lado;
}
class Esfera extends Tridimensional{
   private $radio
}