polymorphism - c# List of derived class -


i'm developing c# winform application work, i'm stuck , don't know best way proceed on. here's snippet of code

class block() {    // generic block properties }  class ablock() : block {     // specific ablock stuff }  class bblock() : block {     // specific bblock stuff }   abstract class algorithm() {    // generic algorithm properties    abstract list<block> blocklist // ?? }  class aalgorithm() : algorithm {     // specific aalgorithm stuff     list<ablock> blocklist // ?? }  class balgorithm() : algorithm {     // specific balgorithm stuff     list<ablock> blocklist // ?? } 

i think situation pretty simple: every derived class of algorithm has it's own derived class of block, want make generic , accessible list<block> blocklist in asbtract class algorithm. think it's common situation , i'm sure there solution.

thanks in advance

i might missing something, couldn't make abstract property?

abstract class algorithm() {    abstract list<block> blocklist { get; } } 

... when, writing class derives algorithm, won't compile unless blocklist.get implemented:

public class algorithma : algorithm {     public override list<block> blocks     {                 {             return new list<block> { new ablock(), new ablock() };         }     } } 

about blemish that, if code within algorithma wants use blocks property, might need cast (ablock).


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -