Refactoring -Code zur Entkopplung von Abhängigkeiten [geschlossen]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Refactoring -Code zur Entkopplung von Abhängigkeiten [geschlossen]

Post by Anonymous »

Betrachten Sie die folgende Klasse: < /p>

Code: Select all

public readonly struct Shape
{
public void Render (Graphics graphics)
{
// Do complex manipulation to draw the shape using the `graphics` object.
graphics.DrawLine(Pens.Red, this.Point1, this.Point2);
graphics.DrawLine(Pens.Red, this.Point2, this.Point3);
...
}
}
< /code>
und der aufrufende Code aus einer WinForms -App: < /p>
private void PictureBox_Paint (object? sender, PaintEventArgs e)
{
var shape = new Shape(...);

shape.Render(e.Graphics);
}
Die Form kümmert sich um ihre eigene Renderung und hält den Anrufcode einfach. Ein Verweis auf das Objekt von Grafiken in der Form ist jedoch eine rote Flag, da diese App in Zukunft auf mehrere Plattformen abzielt. Dies, um die Klassen locker gekoppelt zu halten?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post