06.
Abstract Classes
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
14 Comments
Hello, I have a question about challenge 1 related to chapter 6 “Abstract Classes”, the type of the object (argument)can be all classes except GreatClass.
I don t understand why we have only chosen MyClass and Puppy and not the others. if we have the possibility to select multi values from the answers, will be correct if we choose A,B, and C. The question is about type hinting the argument not about its instantiation. Am I missing something ?
Hey Hanane K.
In this case you can't pass objects of the class
OtherClassbecause it's an abstract class. PHP do not allow you to instantiate abstract classes, only concrete classes.That's the reason why the other options are incorrect
I hope it made things clearer. Cheers!
Hello, thanks for your response. when you say « you can't pass objects of the class OtherClass because it's an abstract class » you mean that we can not type-hint an argument using AbstractClass ?
it’s not yet clear for me, because in the video, we passed an object of class AbstractShip to battle function for example and it works.
Oh, no, sorry, I didn't mean that. What I meant is that you can't create objects of an abstract class. e.g.
but you can type-hint arguments with such class so any other class that inherits from it can be passed in. Is it clearer now? If not, let me know :)
Hello, yes it's clear now. Thanks
The exercise for the previous video asked students to use the abstract keyword, but the keyword wasn't explained until this lesson.
Hey Kieran!
Actually, it's subtle, but I think that's not true. On the previous chapter, we create class with the word "abstract" in it, but we don't actually have you use the "abstract" keyword in the challenges until this chapter. But if I'm wrong, please tell me! Or, if we can make some wording more clear for others, awesome too!
Cheers!
The previous exercise throws an error if the class is not defined as abstract, which is a keyword learned on this chapter.
You're right! Thanks for pointing that out - we'll get that check for
abstracttaken out of there :)It's still there.
Yep... it's still a TODO internally :). We've just recently started pushing more on our challenges. Sorry for the delay!
Challenge 1 is a bit confusing. OtherClass can't be instantiated, so doSomething can't be called with an OtherClass object.
Ah, fair point! I was thinking "instances / sub-classes" of OtherClass can be passed to doSomething(). But you're absolutely right - technically you cannot have an OtherClass object, so it should not be an answer. We'll update that - it makes the question even trickier I think, which is kinda cool :)
Thanks!
Thanks again Kieran for the note - we've just updated the first challenge!
"Houston: no signs of life"
Start the conversation!