473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Rules of abstract class

what are the parameter of creating abstract class and how we use in real time ?
Jun 18 '17 #1
3 1783
chaarmann
785 Expert 512MB
There are no "parameter". You just put "abstract" in front of "class".
It doesn't matter if you use it in real time or normal time.
Just write a second class that extends your abstract class and implement the abstract method of your abstract class, That's all how to use it.
Jun 19 '17 #2
i am asking how to use abstract class and in which case i have to use abstract class what are the rules we have to follow before implementing abstract class.
Jun 23 '17 #3
chaarmann
785 Expert 512MB
The coding rule: if the class is abstract, you should start the class name with "Abstract".
Use case: For example you have a problem that you can solve with the state pattern (see wiki)
Then you have many states derived from one abstract State.
Example:
Let's say a wizard can transform himself into an animal.
The you have classes BirdState, CatState and SnakeState. You should derive them all from class AbstractState.
In Abstract state, you write an abstract method getName().
So every derived class is forced to implement it. So if you write a new DogState, you MUST write the getName() method there, else you cannot compile.
In AbstractState, you put the default behaviour, for example the method canFly() that returns false. Then you only override this method in all classes with anmals that can fly, in our case the BirdState.canFly() retuns true. The good thing is that if you add your DogState, then you don not need to write the canFly() method. So if someone calls dog.canFly(), it returns false automatically, as defined in the abstract state.
Jun 23 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that...
16
by: Merlin | last post by:
Hi Been reading the GOF book and started to make the distinction between Class and Interface inheritance. One question though: Do pure abstract classes have representations? (data members?)...
8
by: Claire | last post by:
I have a base abstract class A which contains several abstract functions I then have an abstract class B (derived from A) which overrides a small subset of A's abstract functions Finally I...
6
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove...
9
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must...
10
by: Brett | last post by:
I'm still trying to figure out concrete reasons to use one over the other. I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract...
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
0
by: Craig Buchanan | last post by:
i am trying to build an application that uses plugins to extend the business functionality of an application. i've decided to use inheritance of abstract classes as the mechanism to do this. ...
4
by: N.RATNAKAR | last post by:
hai, what is abstract class and abstract method
5
by: tshad | last post by:
In VS 2003, I am setting up an abstract class that is setting up classes for each datatype of VB.Net (as well as C#). I am trying to set it up so that most of the work is done in the Abstract...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.