Войти в систему

Home
    - Создать дневник
    - Написать в дневник
       - Подробный режим

LJ.Rossia.org
    - Новости сайта
    - Общие настройки
    - Sitemap
    - Оплата
    - ljr-fif

Редактировать...
    - Настройки
    - Список друзей
    - Дневник
    - Картинки
    - Пароль
    - Вид дневника

Сообщества

Настроить S2

Помощь
    - Забыли пароль?
    - FAQ
    - Тех. поддержка



Пишет kouzdra ([info]kouzdra)
@ 2013-07-06 10:33:00


Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Entry tags:go, goбьектное, Компутерщина

goбъектное-2
Приведу пример с множественным наследованием (описания из предыдущего поста предполагаются):

type Colored interface {
   color () string
}

type ColoredPoint interface {
	Point
	Colored
}

func prColAndAbs(cp ColoredPoint) {
	fmt.Printf("Color: %s, Abs: %g\n", cp.color(), cp.abs ())
}

type Color struct {
	string
}

func (c Color) color () string {
    return c.string
}

type ColoredPoint2D struct {
	Point2D
	Color
}

type ColoredPoint3D struct {
	Point3D
	Color
}

func main() {
	p2 := Point2D {1, 2}
	p3 := Point3D {p2, 3}
	cp2 := ColoredPoint2D {p2, Color{"red"}}
	cp3 := ColoredPoint3D {p3, Color{"green"}}
	prColAndAbs(cp2)
	prColAndAbs(cp3)
}


В особых пояснениях, думаю, не нуждается.