Тёмный

Dart Abstract Class and Abstract Method Example. Object Oriented Tutorial #9.6 

Smartherd
Подписаться 136 тыс.
Просмотров 49 тыс.
50% 1

Опубликовано:

 

18 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 41   
@SheikhAmeen
@SheikhAmeen 4 года назад
The use of an abstract class and method: Now, suppose you have a parent Animal class. And two children, Cat and Dog, extending Animal. We may want to create Cat and Dog objects, but we almost will never be creating any Animal objects. We only have the Animal class for the children to inherit from it. Since there's no use for instantiating an Animal class on its own, we make it abstract. And an abstract class cannot be instantiated in the main() function. Now let's see abstract methods.. A Cat and a Dog may have the same function named "makeNoise()", but both of them make different noises. So an abstract method is defined in the abstract class, and we override that method in the child classes. I hope this helps. :)
@congtoannguyen1940
@congtoannguyen1940 2 года назад
Can you tell me the use of Interfaces too
@karimmakki7225
@karimmakki7225 2 года назад
You are the best dude!
@nilavarasu4332
@nilavarasu4332 Год назад
wow thanks!
@psychopath4351
@psychopath4351 Год назад
You're simply the best!!!
@Donut_melodies
@Donut_melodies Год назад
Wohh good example hah.
@aman66939
@aman66939 5 лет назад
Firstly, you r awesome at understanding. What is the use of abstract class then?
@kaiparado
@kaiparado 2 года назад
same doubt
@a.k8779
@a.k8779 2 года назад
Say for example you are making an app ,and their are many teams for that .You are making the design that each page in the app must have several features mandatory like title , chat bot , side bar so you will make an abstract class and will define abstract methods like title, sidebar, chatbot . Each team, who works on different pages of the app must inherit this class and while doing this they are forced to obey these features. That is abstract methods it compulsory that you maut add that methos in all inheriting classes
@a.k8779
@a.k8779 2 года назад
@@kaiparado Say for example you are making an app ,and their are many teams for that .You are making the design that each page in the app must have several features mandatory like title , chat bot , side bar so you will make an abstract class and will define abstract methods like title, sidebar, chatbot . Each team, who works on different pages of the app must inherit this class and while doing this they are forced to obey these features. That is abstract methods it compulsory that you maut add that methos in all inheriting classes
@sagarghare9829
@sagarghare9829 4 года назад
Lockdown time learning dart . very similar to java. Thanks for the series. I like your plain voice.
@DevidBorethLock
@DevidBorethLock Год назад
Super Clear Explanation
@nasirmehmood_
@nasirmehmood_ 4 года назад
simple clear and precise. Awesome. God bless you man.
@muneebkhannn
@muneebkhannn Год назад
kya krrao bhaii ab 3 saal hgye ab to
@marshalkamal7117
@marshalkamal7117 Год назад
you are such a legend
@avi8034
@avi8034 4 года назад
Sir as you said , after inheriting the abstract class and its method , we can use another method in abstract class with body but what is the purpose of using a method with body in an abstract class when it can not be instantiated ?
@AA-tv3eu
@AA-tv3eu 3 года назад
actually you have to call that method with the object of child class. like a method eat can have body in abstract class of animal so we can call that eat method by object of child class like cat.eat();
@ujjawalk6780
@ujjawalk6780 5 лет назад
Sir if we can't instantiate an abstract class then why it instantiated when we instantiate the child class of it.
@jemjem8902
@jemjem8902 7 месяцев назад
What's the difference from using an interface other than you can implement multiple interfaces.
@itubezonebd
@itubezonebd 5 лет назад
Hi, Sir I want to know what are application and benefit of abstract classes?
@王甯-h2x
@王甯-h2x 5 лет назад
I will recommend you just remember you can't instantiate an object of an abstract class, and search about the difference between abstract class and interface.
@VivekYadav-ds8oz
@VivekYadav-ds8oz 4 года назад
It is helpful if you need to make a generic function that can take a lot of class types as an argument. Eg: abstract class Shape { void area(); void perimeter(); } class Rectangle extends Shape { int width; int height; Rectangle(this.width, this.height); void area() => this.width * this.height; void perimeter() => 2*(this.width + this.height); } class Triangle extends Shape { int side1; int side2; int side3; Triangle(this.side1, this.side2, this.side3); void area() => 0.5 * this.side1 * this.side2 * this.side3; void perimeter() => this.side1 + this.side2 + this.side3; } void printGeometry(Shape shape) { print("The area of this shape is ${shape.area()}";) print("The perimeter of this shape is ${shape.perimeter()}";) }
@simonebranca1972
@simonebranca1972 4 года назад
Abstract Classes are usefull for code organization i.e. Contracts: Abstract Classes One way a contract is implemented is via an abstract class. An abstract class is a class that contains one or more methods that do not have any implementation provided. Suppose that you have an abstract class called Shape. It is abstract because you cannot instantiate it. If you ask someone to draw a shape, the first thing they will most likely ask you is "What kind of shape?" Thus, the concept of a shape is abstract. However, if someone asks you to draw a circle, this does not pose quite the same problem because a circle is a concrete concept. You know what a circle looks like. You also know how to draw other shapes, such as rectangles. How does this apply to a contract? Let's assume that we want to create an application to draw shapes. Our goal is to draw every kind of shape represented in our current design, as well as ones that might be added later. There are two conditions we must adhere to. First, we want all shapes to use the same syntax to draw themselves. For example, we want every shape implemented in our system to contain a method called draw(). Thus, seasoned developers implicitly know that to draw a shape you simply invoke the draw() method, regardless of what the shape happens to be. Theoretically, this reduces the amount of time spent fumbling through manuals and cuts down on syntax errors. Second, remember that it is important that every class be responsible for its own actions. Thus, even though a class is required to provide a method called draw(), that class must provide its own implementation of the code. For example, the classes Circle and Rectangle both have a draw() method; however, the Circle class obviously has code to draw a circle, and as expected, the Rectangle class has code to draw a rectangle. When we ultimately create classes called Circle and Rectangle, which are subclasses of Shape, these classes must implement their own version of Draw
@makiss9361
@makiss9361 4 года назад
@@simonebranca1972 Great explanation ! Thanks ...
@roverojermainemariongilr.2856
@roverojermainemariongilr.2856 2 года назад
@@simonebranca1972 Great explanation! Thanks for this
@korouiromcha8211
@korouiromcha8211 4 года назад
yes, I wanted to know that if we are about to create another class as we can't use abstract class directly, then why create abstract class?
@yakine13
@yakine13 4 года назад
same question
@SammarpanDasguptaOfficial
@SammarpanDasguptaOfficial 3 года назад
We can make the child class of the abstract parent class.....Suppose you have some properties and methods present in abstract parent class..and you want these properties and methods only usable by child class but not by object of that abstract parent class....that's why we make the abstract class...
@karthickrajalearn
@karthickrajalearn 5 лет назад
In 3m 39sec Great Tip
@noob_gamer07
@noob_gamer07 5 лет назад
abstract class can have constructs with just declarations
@jadoooh55
@jadoooh55 5 лет назад
abstract extends, interface implements :)
@venkateshwarlumotamari5488
@venkateshwarlumotamari5488 6 лет назад
sir , in Abstract Class you have declared x and y, can we use Abstract Class instance variables in Circle child class ?
@thebigbeast578
@thebigbeast578 4 года назад
Yes, but you have to override
@kasandrop
@kasandrop 3 года назад
You did not mention anything about method declaration. what about overriding an abstract method with different list of arguments??? Is that allowed? Hmm.
@muralidharan2044
@muralidharan2044 4 года назад
its not mandatory to have abstract method in abstract class. then y we use abstract class. you are only telling how to type syntax. but u never show an example or scenario where it can work. try this code with out abstract method in abs, class it works..... void main() { var dog = Dog(); dog.shape(); } abstract class Animal { void shape() { print("hwwwwwwwwwwwwwwwwwww"); } } class Dog extends Animal { void shape(); }
@MrAwaisChand
@MrAwaisChand Год назад
tell me what's your editor name
@mazenalsakkaf
@mazenalsakkaf 5 лет назад
If you are designing large functional units, use an abstract class. If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members. LINK: www.codementor.io/vipinc/when-to-use-abstract-classes-and-when-interfaces-c-interview-questions-jtzll1sn7
@niteshkhatri6224
@niteshkhatri6224 4 года назад
i wonder if you know this much why are you watching this tutorial.
@ujjawalk6780
@ujjawalk6780 5 лет назад
Because the constructor is called when the child class is instantiated.
@akshaybhandari8951
@akshaybhandari8951 2 года назад
Can someone explain the exact usage of method() :someNewWork() { \\Whatever} What is the real world usage of the stuff after colon?
Далее
Fundamental Concepts of Object Oriented Programming
9:16