Last active
April 15, 2024 03:51
-
-
Save YurePereira/8bbc48ddf699d451bf1607cbef58ab9a to your computer and use it in GitHub Desktop.
Podemos fazer com que uma classe não possa ser mais herdando usando o modificador sealed, pouco conhecimento, mas algo muito usual para quem quer construir objetos de valor (value object) consistentes e impedir que outras classes dentro da arquitetura do projeto as herdem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
//Testando: | |
var dog = new Dog(); | |
dog.Start(); | |
dog.Stop(); | |
} | |
public class Walk { | |
public double Speed { get; set; } | |
public void Start() | |
{ | |
Console.WriteLine("Walking!"); | |
} | |
public void Stop() | |
{ | |
Console.WriteLine("Stopping walking!"); | |
} | |
} | |
public sealed class Dog : Walk {} | |
public sealed class Cat : Walk {} | |
//Erro de compilação: | |
public sealed class Puppy : Cat {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment