subclassResponsibility
Hello, I have created a class which will have many subclasses some of which will have subclasses of their own. I want every single class to implement a class method #shortName which will provide a short string as a human readable short identifier to the object. I have in the highest superClass shortName    self subclassResponsibility But the moment I implement it in a subclass which has subclasses. Those subclasses are now using their closest superClasses implementation. Is there a way force allSubclasses to implement the method? Thanks. Jimmie
Is there a way force allSubclasses to implement the method? No. Pretty much, you need to avoid subclassing concrete classes. i.e. if A has subclasses B and C, refactor to create an abstract A' and move A to be a leaf subclass of A'. -----Original Message----- From: Jimmie Houchin [mailto:jlhouchin@gmail.com] Sent: December 22, 2020 15:08 To: Any question about pharo is welcome Subject: [Pharo-users] subclassResponsibility Hello, I have created a class which will have many subclasses some of which will have subclasses of their own. I want every single class to implement a class method #shortName which will provide a short string as a human readable short identifier to the object. I have in the highest superClass shortName    self subclassResponsibility But the moment I implement it in a subclass which has subclasses. Those subclasses are now using their closest superClasses implementation. Is there a way force allSubclasses to implement the method? Thanks. Jimmie
I didn't thinks so, but was not sure. I have not done much with Abstract classes. I will have to think about that and its design implications. Thanks for the suggestion. Jimmie On 12/22/20 8:01 PM, Richard Sargent wrote:
Is there a way force allSubclasses to implement the method?
No. Pretty much, you need to avoid subclassing concrete classes. i.e. if A has subclasses B and C, refactor to create an abstract A' and move A to be a leaf subclass of A'.
-----Original Message----- From: Jimmie Houchin [mailto:jlhouchin@gmail.com] Sent: December 22, 2020 15:08 To: Any question about pharo is welcome Subject: [Pharo-users] subclassResponsibility
Hello,
I have created a class which will have many subclasses some of which will have subclasses of their own.
I want every single class to implement a class method #shortName which will provide a short string as a human readable short identifier to the object.
I have in the highest superClass
shortName
   self subclassResponsibility
But the moment I implement it in a subclass which has subclasses. Those subclasses are now using their closest superClasses implementation.
Is there a way force allSubclasses to implement the method?
Thanks.
Jimmie
participants (2)
-
Jimmie Houchin -
Richard Sargent