Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6909177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:39:24+00:00 2026-05-27T08:39:24+00:00

I have some problem to find oop information about my problem in scala, peraphs

  • 0

I have some problem to find oop information about my problem in scala, peraphs you can help me to find a good solution, or good web/book ressources ?

I have one principal abstract class Operator :

abstract class Operator[G <: AbstractGenome, F <: GenomeFactory[G]] {
  implicit val factory: F
  def operate (genomes: IndexedSeq[G])
}

and two other inherited abstract class :

abstract class Mutation [G <: AbstractGenome, F <: GenomeFactory [G]]  
  extends Operator [G, F] {
  override def operate (genomes: IndexedSeq[G]):G
}

abstract class CrossOver [G <: AbstractGenome, F <: GenomeFactory [G]]
  extends Operator [G, F] {
  override def operate (genomes: IndexedSeq[G]) (implicit aprng : Random):IndexedSeq[G]
  }

My problem is here, i cannot override the method operate(..) with different return type when i try to instancite these abstract class, this code doesn’t work.

I have already multiple lines of code which use the mutation operate() method which return an unique Genome G … Can i conserve this OOP structure by using a wrapper, an intermediate object to catch my genome, and bypass this problem with also a generic structure ?

Thanks a lot for your lights,
SR.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:39:25+00:00Added an answer on May 27, 2026 at 8:39 am

    If you do not provide a return type for an abstract method Unit is used – not Any as you might have assumed. Just change the declaration in Operator to

    def operate(genomes: IndexedSeq[G]): Any
    

    This will not work in the second case though as you cannot add parameter lists when overriding methods. You will have to provide the implicit parameter via the constructor or add it to the declaration in the base class.

    The easiest way to implement this would be to add a type parameter for your return type to Operation and put the implicit parameters needed for a specific instance to the constructor of your implementation, e.g.

    abstract class Operator[G <: AbstractGenome, F <: GenomeFactory[G], R] {
      implicit val factory: F
      def operate (genomes: IndexedSeq[G]): R
    }
    
    class CrossOver[G <: AbstractGenome, F <: GenomeFactory [G]](implicit r: Random)
      extends Operator [G, F, IndexedSeq[G]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem with has_many_polymorphs, maybe you can help me. I have some models
simple question maybe but can't find solution. I have button for refresh/update some contents
I have a simple problem that I cannot seem to find a solution to.
Where can I find some good, proven guidelines or examples on writing extensible, modular,
I'm using System.Web.Routing to have some better URL's and have come across a problem.
I'm trying to find an elegant OOP solution for the following problem. Assume we
I have some problem to figure out how I can maintain the pipe and
I have some problem with PostSharp (I assume that problem can be solved by
I have searched on here for some time and can't find a specific answer
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.