giacomelli / GeneticSharp

GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).
MIT License
1.27k stars 332 forks source link

Make struct Gene Generic #48

Closed FrediKats closed 5 years ago

FrediKats commented 5 years ago

Struct Gene isn't generic. It's probably not type-safed.

First solution

class Gene<T>
{ 
        public T Value => m_value;
        public Gene<T>(T value)
        {
                m_value = value;
        }
}
giacomelli commented 5 years ago

The Gene is not generic because a chromosome could be made for genes of different kind o values: int, float, double, char, any type o class.

If you made it generic will have problems with simple things, like this method on the IChromosome interface:

/// <summary>
/// Gets the genes.
/// </summary>
/// <returns>The genes.</returns>
Gene[] GetGenes();
AnakinCN commented 1 year ago

The Gene is not generic because a chromosome could be made for genes of different kind o values: int, float, double, char, any type o class.

If you made it generic will have problems with simple things, like this method on the IChromosome interface:

/// <summary>
/// Gets the genes.
/// </summary>
/// <returns>The genes.</returns>
Gene[] GetGenes();

maybe return List\<T> then, where T : IGene