Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
Questionquestion re abstract class with no implementation allowing an abstract property to be set in the 'cTor Pin
BillWoodruff10-Nov-14 6:25
professionalBillWoodruff10-Nov-14 6:25 
AnswerRe: question re abstract class with no implementation allowing an abstract property to be set in the 'cTor Pin
Richard MacCutchan10-Nov-14 7:08
mveRichard MacCutchan10-Nov-14 7:08 
SuggestionRe: question re abstract class with no implementation allowing an abstract property to be set in the 'cTor Pin
Richard Deeming10-Nov-14 8:08
mveRichard Deeming10-Nov-14 8:08 
GeneralRe: question re abstract class with no implementation allowing an abstract property to be set in the 'cTor Pin
Sergey Alexandrovich Kryukov10-Nov-14 10:05
mvaSergey Alexandrovich Kryukov10-Nov-14 10:05 
GeneralRe: question re abstract class with no implementation allowing an abstract property to be set in the 'cTor Pin
Richard Deeming10-Nov-14 10:13
mveRichard Deeming10-Nov-14 10:13 
GeneralSure Pin
Sergey Alexandrovich Kryukov10-Nov-14 10:17
mvaSergey Alexandrovich Kryukov10-Nov-14 10:17 
AnswerRe: question re abstract class with no implementation allowing an abstract property to be set in the 'cTor Pin
OriginalGriff10-Nov-14 8:14
mveOriginalGriff10-Nov-14 8:14 
AnswerIt makes perfect sense! Pin
Sergey Alexandrovich Kryukov10-Nov-14 8:26
mvaSergey Alexandrovich Kryukov10-Nov-14 8:26 
It makes perfect sense. I just changed my comment to the wrong Mehdi's post and stated: abstract class is not a placeholder, not even close. I explained what it is and what is its purpose. And it should add: it should not be used as a substitute of interface.

Having non-abstract methods in an abstract class has more than perfect sense. Such methods are inherited and can be used in derived classes (so they should better be protected). Internal and public methods are even more important: the compile-time type of abstract class is usually used as a base class for some hierarchy of terminal derived classes used in polymorphic set. This is how you work with derived classed: through members of the base class. If such base class method uses virtual methods, late binging mechanism dispatch the calls to the methods of derived classes, so the whole OOP mechanism is leveraged.

There are many cases when this method in abstract class need not to be overridden, therefore, there is no a need to make it virtual or abstract (all abstract methods are of course virtual).

This is the very basic approach in OOD every developer should know and use.

[EDIT]

Now, let me explain why there is no danger in your assignment of the abstract property in a non-abstract (and even non-virtual) method NoImplementations:
This is an instance method. As an instance method, it will need an instance to be called on. Such instance will always be an instance of some derived non-abstract type, because an abstract type won't allow to get an instance. And, such non-abstract type could not be created if SomeInt is not given the implementation. The mechanism of the late binding will use the virtual method table for the setter of SomeInt, according to the runtime type of that non-abstract derived type. Therefore, in all cases where NoImplementations can be called, the setter of SomeInt can also be correctly called and actually assign the property value. No problems whatsoever.

—SA
Sergey A Kryukov


modified 10-Nov-14 17:39pm.

GeneralRe: It makes perfect sense! Pin
Brisingr Aerowing10-Nov-14 8:36
professionalBrisingr Aerowing10-Nov-14 8:36 
GeneralRe: It makes perfect sense! Pin
Eddy Vluggen10-Nov-14 8:43
professionalEddy Vluggen10-Nov-14 8:43 
GeneralPerverted understanding of "democracy" Pin
Sergey Alexandrovich Kryukov10-Nov-14 9:57
mvaSergey Alexandrovich Kryukov10-Nov-14 9:57 
GeneralRe: Perverted understanding of "democracy" Pin
Eddy Vluggen10-Nov-14 12:58
professionalEddy Vluggen10-Nov-14 12:58 
GeneralRe: Perverted understanding of "democracy" Pin
Sergey Alexandrovich Kryukov10-Nov-14 13:07
mvaSergey Alexandrovich Kryukov10-Nov-14 13:07 
GeneralRe: Perverted understanding of "democracy" Pin
Eddy Vluggen11-Nov-14 0:32
professionalEddy Vluggen11-Nov-14 0:32 
GeneralRe: Perverted understanding of "democracy" Pin
Sergey Alexandrovich Kryukov11-Nov-14 3:54
mvaSergey Alexandrovich Kryukov11-Nov-14 3:54 
GeneralRe: It makes perfect sense! Pin
Eddy Vluggen10-Nov-14 8:40
professionalEddy Vluggen10-Nov-14 8:40 
GeneralThis is a confession Pin
Sergey Alexandrovich Kryukov10-Nov-14 10:01
mvaSergey Alexandrovich Kryukov10-Nov-14 10:01 
QuestionRe: This is a confession Pin
Eddy Vluggen10-Nov-14 12:56
professionalEddy Vluggen10-Nov-14 12:56 
AnswerRe: This is a confession Pin
Sergey Alexandrovich Kryukov10-Nov-14 13:05
mvaSergey Alexandrovich Kryukov10-Nov-14 13:05 
AnswerRe: This is a confession Pin
Richard MacCutchan10-Nov-14 21:32
mveRichard MacCutchan10-Nov-14 21:32 
QuestionHow to find the nearest number that divides evenly in to another number. Pin
Member 1122095210-Nov-14 0:03
Member 1122095210-Nov-14 0:03 
QuestionRe: How to find the nearest number that divides evenly in to another number. Pin
Richard MacCutchan10-Nov-14 2:14
mveRichard MacCutchan10-Nov-14 2:14 
AnswerRe: How to find the nearest number that divides evenly in to another number. Pin
BillWoodruff10-Nov-14 2:53
professionalBillWoodruff10-Nov-14 2:53 
AnswerRe: How to find the nearest number that divides evenly in to another number. Pin
Dominic Burford10-Nov-14 2:54
professionalDominic Burford10-Nov-14 2:54 
AnswerRe: How to find the nearest number that divides evenly in to another number. Pin
Ravi Bhavnani10-Nov-14 6:00
professionalRavi Bhavnani10-Nov-14 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.