Похожие чаты

Hello, a small typescript question. I have the following structure and

I don't know how to express this best using classes and TS.

- Parent does not have property x.
- child 1 has private property x, and a method using it.
- child 2 has private property x, and the SAME method using it.

How do I define the method in the parent to decrease code repetition, while keeping the property x, specific to the children?

2 ответов

13 просмотров

Welcome to a problem that OOP introduces - constantly coming up with new classes with arbitrary names in order to find a common parent for inheritance. What you probably need is composition instead of inheritance. youtube.com/watch?v=wfMtDGfHWpA In classes, re-using methods is not possible (unless you inherit them). The only abstraction layer you have are objects and classes. you either HAVE to redeclare them - duplicating yourself - or use inheritance.

Emre- Автор вопроса

Похожие вопросы

Обсуждают сегодня

я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
49
30 BCH videos in Hausa Language successfully delivered. In December 2023, I created a Flipstarter to produce Bitcoin Cash videos in the Hausa language for greater outreach an...
Munnir
5
читать файл максимально быстро? странный вопрос))
zamtmn
53
Интересно, а майкрософт 365 может запустится на линукс минт?
Лисицка
17
Всем доброго вечера! Хочу поделиться своим злоключением с человеком, который, как оказалось сюда тоже скидывал свое резюме. Жаль, что я вашу группу не нашел раньше… человек ки...
Роман Ахмедзянов
4
How to create an OS in C? what to study?
Linus
18
Компания Elif ищет менеджера проектов, который будет заниматься поиском и ведением новых проектов. Прежде чем приступить к работе, вам нужно пройти наш недельный курс, где вы ...
Elif
5
братва! где куличи брать?
Alöscha
25
тоесть, указав return eax, сгенерируется никому ненужная инструкция mov eax,eax ?
Aiwan \ (•◡•) / _bot
24
@admin main apna email bhul Gaya number se kasy login kare Wazirx ?
Shamim Iqbal
14
Карта сайта