Home
Blogs
Questions
Jobs
Monetize

Home

About Us

Blogs

Questions

Jobs

Monetize

Post Job

banner

Questions about duck-typing

Read more about duck-typing

python (65.2k questions)

javascript (44.3k questions)

reactjs (22.7k questions)

java (20.8k questions)

c# (17.4k questions)

html (16.3k questions)

r (13.7k questions)

android (13k questions)

Questions - duck-typing

How to avoid if..else(or any conditionals) while deciding which method to be called?

How to follow Open Close Principle without violating LSP while deciding which method to be invoked with different parameters in a statically typed language? Consider the requirement like Action 1: pe...
test-img

Mani

oop

if-statement

duck-typing

liskov-substitution-principle

open-closed-principle

Votes: 0

Answers: 2

Latest Answer

A simple solution would be to define a strategy, which execute the code currently contained in the if / else if / else branches: interface Strategy { String getType(); void apply(); } The strateg...
test-img

Florian Salihovic

How do I get mypy to recognize that an argument of a function needs to be a subclass of a particular base class?

How do I get mypy to recognize that an argument of a function needs to be a subclass of a particular base class? Consider the following: # main.py class A: ... class B(A): def f(self, x): prin...
test-img

user32882

python

static-analysis

type-hinting

mypy

duck-typing

Votes: 0

Answers: 1

Latest Answer

I suppose that taking a stab at an answer isn't a bad idea at this point, since I have enough information from the comments. You need to first enforce that f is implemented by subclasses of A. Otherwi...
test-img

BrokenBenchmark

Posts

Questions

Blogs

Jobs

The ultimate platform for coders and IT specialists

About

  • Company
  • Support

  • Platform

  • Terms & Conditions
  • Privacy statement
  • Cookie policy
  • Cookie option
  • OnlyCoders © 2025  |  All rights reserved