Imports System.Drawing

Public MustInherit Class Triangle
  Private p1, p2, p3 As Point
  Protected bPen As Pen
  '-----
  Public Sub New(ByVal a As Point, ByVal b As Point, _
           ByVal c As Point)
    p1 = a
    p2 = b
    p3 = c
    bPen = New Pen(Color.Black)
  End Sub
  '-----
  'Narysuj kompletny trójkąt
  Public Sub draw(ByVal g As Graphics)
    drawLine(g, p1, p2)
    Dim c As Point = draw2ndLine(g, p2, p3)
    closeTriangle(g, c)
  End Sub
  '-----
  'Rysuj jeden bok trójkąta
  Public Sub drawLine(ByVal g As Graphics, ByVal a As Point, _
          ByRef b As Point)
    g.DrawLine(bPen, a.X, a.Y, b.X, b.Y)
  End Sub
  '-----
  'Metoda, którą należy zastąpić w klasie pochodnej
  Public MustOverride Function draw2ndLine(ByVal g As Graphics, _
      ByVal a As Point, ByVal b As Point) As Point
  '-----
  'Rysuje ostatni bok trójkąta
  Public Sub closeTriangle(ByVal g As Graphics, ByVal c As Point)
    g.DrawLine(bPen, c.X, c.Y, p1.X, p1.Y)
  End Sub
End Class
