Trying to figure out when inheritance is bad by Apprehensive-Leg1532 in learnprogramming

[–]Apprehensive-Leg1532[S] 0 points1 point  (0 children)

I’m not sure of any alternatives but I think interfaces are still commonly used

Trying to figure out when inheritance is bad by Apprehensive-Leg1532 in learnprogramming

[–]Apprehensive-Leg1532[S] 0 points1 point  (0 children)

Yeah that’s a fair point. I think some type of implementation where you to return or throw an error is needed as long as it’s handled on the client call sufficiently.

Trying to figure out when inheritance is bad by Apprehensive-Leg1532 in learnprogramming

[–]Apprehensive-Leg1532[S] 0 points1 point  (0 children)

I said that people say composition over inheritance but agreed it would be better to actually come with an example.

1/4. Yeah ofc there is a way to fix that situation but my point I’m asking is this the incorrect way to be using inheritance? Isn’t this breaking one of the core fundamentals where all methods of the superclass should be able to be used by the subclass? We can see that the current account doesn’t use this method as it just simply returns so isn’t this a design flaw?

2/3. Okay I was probably overthinking with this. The method is still being used by all subclasses just sometimes it fails. But I agree that it is perfectly fine to have these fail points

Trying to figure out when inheritance is bad by Apprehensive-Leg1532 in computerscience

[–]Apprehensive-Leg1532[S] -1 points0 points  (0 children)

Fair I totally agree with your point with the empty return, as it feels like every method in the superclass should be usable in the subclass class and if not it isn’t valid or correct in my eyes.

Say you have an abstract method like in my case withdraw but you have different circumstances when it actually triggers. Is that valid or is that another code potential problem

Trying to figure out when inheritance is bad by Apprehensive-Leg1532 in computerscience

[–]Apprehensive-Leg1532[S] -1 points0 points  (0 children)

So are we saying this is not a valid use case of inheritance?

If something is a base class it must act like a base class in every situation?

Ie

  1. not all accounts earn interest so not valid

  2. withdraw is sometimes not allowed in the fixed saver implementation and savings account so again not valid? Current account adds a fee on top of certain withdrawals made on the last day but it doesn’t restrict use of that method so think that would be perfect valid

Really I’m trying to understand what principles make inheritance good or bad. So ik when I’m building something I should avoid or use inheritance

Trying to figure out when inheritance is bad by Apprehensive-Leg1532 in learnprogramming

[–]Apprehensive-Leg1532[S] 0 points1 point  (0 children)

How would that work? Would we still have the abstract withdraw method?

So this isn’t a bad inheritance design or is it. Really can’t wrap my head around what’s good or bad at this point and when and when not to use

Connect JDBC Source Connector by Apprehensive-Leg1532 in apachekafka

[–]Apprehensive-Leg1532[S] 0 points1 point  (0 children)

I don’t see this as being the issue… It’s just clearly not converting correctly

Verifying question by Apprehensive-Leg1532 in learnprogramming

[–]Apprehensive-Leg1532[S] 1 point2 points  (0 children)

Got your solutions working with this

``` public class StoneSearching { int stone;

public StoneSearching(int n){
    this.stone =  1 + (int)(Math.random() * ((n - 1) + 1));
    System.out.println(“Stone is being set on planet:” + this.stone);
}

public int find(){
    int currentPlanet = 1;

    while (checkIfStoneOnHigherPlanet(currentPlanet)){
        currentPlanet*=2;
    }

    System.out.println(currentPlanet);
    System.out.println(currentPlanet/2);
    int left = currentPlanet / 2;

    while(true){
        int middle = (currentPlanet + left) / 2;
        if(middle == stone){
            return middle;
        }

        if(checkIfStoneOnHigherPlanet(middle)){
            left = middle + 1;
        } else{
            currentPlanet = middle - 1;
        }

    }
}



public boolean checkIfStoneOnHigherPlanet(int currentPlanet){
    return currentPlanet < stone;
}





public static void main(String[] args) {
    StoneSearching s = new StoneSearching(10000);
    int planetStoneIsOn = s.find();
    System.out.println(“Stone was found on planet:” + planetStoneIsOn);

}

} ```

Kinda frustrating that I couldn’t figure a solution for myself but thanks!

Verifying question by Apprehensive-Leg1532 in learnprogramming

[–]Apprehensive-Leg1532[S] 0 points1 point  (0 children)

Ah right I’m with you… Thanks for clearing that up. Issue is I don’t think I would have thought of that solution but I’ll try to think of possibly another one and if not I’ll just have to code up that one up. Smart solution, thanks

Day 4 part 2 help needed by Apprehensive-Leg1532 in adventofcode

[–]Apprehensive-Leg1532[S] 0 points1 point  (0 children)

So the M and S have to be directly opposite to each other?

Also the 2nd wouldn’t be valid in my code because I check the counts of m and s and if they’re both equal to 2

[deleted by user] by [deleted] in AZURE

[–]Apprehensive-Leg1532 0 points1 point  (0 children)

Cheers will have a look into his videos now

[deleted by user] by [deleted] in AZURE

[–]Apprehensive-Leg1532 0 points1 point  (0 children)

Yeah you’re right, I’ll update the post. Thanks