|
Difference between Abstract classes and Interface
Little background:
A real world entity is represented in an OOP world as object. Objects are defined as classes any language.
A class defines objects in two aspects
Object's characteristics - Data Members
Object's functionality - Member functions
So, when the classes that are forced to provide implementations of the functions prototypes that are defined in either ‘interfaces’ or a ‘abstract class’ are not belonging to the same family (having some inherited parental characteristics from same parent directly or indirectly) but are rather related through some functionalities then 100% we will go with interface and if above said classes are belonging to same family then we should go with abstract class inheritance.
Also in case of inheritance as everything is a specialization of base parent object so there is allowance of providing some default definitions of the functions that are needed to be implemented further by specialized classes. This is not any way allowed in interfaces because implementing classes are not belonging to same family and are not any way related by characteristics.
An Example:
We have four real world objects:
• Airplane
• Bird
• Sparrow
• Eagle
We have one method that is a functionality of all above objects
• Fly
Now all objects share common functionality flying in air but differ in the mechanism they use to fly.
Also by close look we see that in general there is some common characteristics (as well as some common functionalities) between Sparrow and Eagle that can be a part of common class Bird (that has to be abstract because there is no real thing like bird!). But any way Airplane can't be related to Bird or its specialized classes Sparrow and Eagle.
So if want to expose fly functionality to outer world and want their implementations in Airplane and Sparrow (or any bird), so I will 100% go for Interface and Abstract classes will be a big NO!
But if we exclude Airplane want that fly functionality is exposed to outer world and its implementing classes are Bird, Sparrow and Eagle then 'Abstract Classes' is the best of best choice.
Happy programming! Please feel free in writing to me for further clarifications on other OOP concepts (im.himanshu2006@gmail.com)
Himanshu
|
|
|
|
|
Difference between Abstract classes and Interface
Little background:
A real world entity is represented in an OOP world as object. Objects are defined as classes any language.
A class defines objects in two aspects
Object's characteristics - Data Members
Object's functionality - Member functions
So, when the classes that are forced to provide implementations of the functions prototypes that are defined in either ‘interfaces’ or a ‘abstract class’ are not belonging to the same family (having some inherited parental characteristics from same parent directly or indirectly) but are rather related through some functionalities then 100% we will go with interface and if above said classes are belonging to same family then we should go with abstract class inheritance.
Also in case of inheritance as everything is a specialization of base parent object so there is allowance of providing some default definitions of the functions that are needed to be implemented further by specialized classes. This is not any way allowed in interfaces because implementing classes are not belonging to same family and are not any way related by characteristics.
An Example:
We have four real world objects:
• Airplane
• Bird
• Sparrow
• Eagle
We have one method that is a functionality of all above objects
• Fly
Now all objects share common functionality flying in air but differ in the mechanism they use to fly.
Also by close look we see that in general there is some common characteristics (as well as some common functionalities) between Sparrow and Eagle that can be a part of common class Bird (that has to be abstract because there is no real thing like bird!). But any way Airplane can't be related to Bird or its specialized classes Sparrow and Eagle.
So if want to expose fly functionality to outer world and want their implementations in Airplane and Sparrow (or any bird), so I will 100% go for Interface and Abstract classes will be a big NO!
But if we exclude Airplane want that fly functionality is exposed to outer world and its implementing classes are Bird, Sparrow and Eagle then 'Abstract Classes' is the best of best choice.
Happy programming! Please feel free in writing to me for further clarifications on other OOP concepts (im.himanshu2006@gmail.com)
Himanshu
|
|
|
|
|
i am trying to create an excel like interface where headers must remain still verticaly and the detail section can be scrolled. but when user will scroll detail section horizontly, header section must also scroll accordingly. i have put bot in different rows of tableLayoutPanel and a panel control is containing headers and another panel is containing detail section.
i have also wrote some code in OnScroll event procedure but still unable to achieve my goal.
need help!
*************************
SetNewGoal:
while (GoalNotAchieved){}
goto SetNewGoal;
*************************
|
|
|
|
|
why don't you try modiffying DataGridView?!.. (or DataGrid in framework 1.1)..
life is study!!!
|
|
|
|
|
what i am trying to create is not exactly an excel sheet. basically it is an admin section of Media Schedular Application which shows schedules defined in schedule controls in detail section and the header contains a ruler bar to show the scale in minutes. this schedular shows records for one month and of all four quarters of screen.
i have two panel controls named pnlHeader (no scroll bars) and pnlDetail (both vertical and horizontal scroll bars). when a user scrolls vertically up and down on pnlDetail, there is no effect on pnlHeader but when user will scroll horizontly on pnlDetail the other panel named pnlHeader will also scroll accordingly.
*************************
SetNewGoal:
while (GoalNotAchieved){}
goto SetNewGoal;
*************************
|
|
|
|
|
Hi, I have 2 forms, on one form i want to browse image and want to save them in array or arraylist and show on 2nd form that selected image. How would that be done?
One more query is that if i want to show that image in 2nd form can i set the size of image to be shown in a proper place as thier will be some more images will be later on adding to that form as well.
Please help. Thanks
|
|
|
|
|
private void browseBtn_Click(object sender, EventArgs e)<br />
{<br />
openFile.InitialDirectory = @"C:\";<br />
openFile.Filter = "JPEG files (*.jpg)|*.jpg|GIF files (*.gif)|*.gif | BMP files (*.bmp)|*.bmp";<br />
openFile.FilterIndex = 2;<br />
openFile.RestoreDirectory = true;<br />
if (openFile.ShowDialog() != DialogResult.Cancel)<br />
{<br />
imgTextbox.Text = openFile.FileName;<br />
<br />
}<br />
else<br />
{<br />
imgTextbox.Text = "";<br />
}<br />
<br />
<br />
private void LoadGameButton_Click(object sender, EventArgs e)<br />
{<br />
TicTacToe tic=new TicTacToe(usernametextBox.Text);<br />
tic.Show();<br />
this.Hide();<br />
}
To be more specific the browse action on first form now when i select image in the textbox and click on loadgamebutton that selected image should appear on next form.
I added Picturebox tool on 2nd form as well but dont know know how to implement the above functionality.
Thanks
|
|
|
|
|
Thanks it worked but one more thing is how to give size to that image as it has been passed as a parameter. I want to give specific size to image when its loaded?
Here is my code
<br />
Login.cs<br />
<br />
private void LoadGameButton_Click(object sender, EventArgs e)<br />
{<br />
TicTacToe tic=new TicTacToe(usernametextBox.Text,imgTextbox.Text);<br />
tic.Show();<br />
this.Hide();<br />
}
TicTacToe.cs<br />
<br />
public TicTacToe(string strText,string img)<br />
{<br />
InitializeComponent();<br />
if (strText.Equals(""))<br />
{<br />
label2.Text = "Guest";<br />
}<br />
else<br />
{<br />
label2.Text = strText;<br />
pictureBox1.Load(img);<br />
}<br />
}
|
|
|
|
|
It worked now the image is in proper shape in the picture box but now the next question is
"how u will put them in some arraylist so i can show multiple images at one time in the picturebox on the form".
Thanks
|
|
|
|
|
Any help please..
|
|
|
|
|
PERFECT PERFECT IT WORKED THANKS A MILLION..THANKS THANKS
|
|
|
|
|
Please help
i have a customer id in textbox, a listview listing 2 to 3 items. So what i want is to insert this into a database with out the id on the textbox changing. Which means i want to add 3 rows at the same time, without changing the id in the textbox.
ID on TextBox = 1
Sample on ListView
Name Descr Amount
Mouse Black 20
Keyboard Black 30
USB 256MB 200
This is what i want the output to be like
sample on Database
1 Mouse Black 20
1 Keyboard Black 30
1 USB 256MB 200
Please
Back of i'm coding!!!!
|
|
|
|
|
Suppose:
Text Box = tb
List Box = lb
Pseudo code :
for(int i=0; i<lb.items.count;i++)
{
insert into table (custid, itemid)
values( tb.text, lb.items[i].text)
}
-- modified at 7:37 Wednesday 16th May, 2007
*************************
SetNewGoal:
while (GoalNotAchieved){}
goto SetNewGoal;
*************************
|
|
|
|
|
Thanks
I understand this using a listbox, but i'm using a ListView with 3 column and 2 rows.
So what i want is get Cell1, cell2, and cell3 at the same time and insert them
Aints never sleep at all, so why should I?
|
|
|
|
|
hi
make dataset of ur data...
and update like this
dataadapter.update(dataset);
i.e.
da.update(ds);
|
|
|
|
|
|
Hi all,
i need to update my windows application from clients machine after its deployed.
i got clickonce as an alternative but i couldn't secceed with that, i couldn't make use of that.
Can u pleae tell me wat will be the alternative,
i wanna use WebBrowser Control and work with it, can i do that so?
please help me with suggestions
thnx in advance
prashanth
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
The alternative is to send your client an exe, or run a seperate program which downloads the exe to the right dir, and then deletes the old one/renames the new one to be the actual file Obviously this will not work if the program is running, so you need another update program to do it.
pashitech wrote: i wanna use WebBrowser Control and work with it, can i do that so?
No sure what you mean here, is this a seperate quesiton ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I developed a little tool for organizing and playing mp3 albums and files. To play the files I'm currently using the media player control. In addition to that I want to visualize the currently played mp3 in an 8-band level meter. Can somebody give me a hint?
Need more information?
mweingart
|
|
|
|
|
I already saw it there [^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi,
I did it, beacause I don't care the language (C# or VB.NET)!
|
|
|
|
|
The regulars around here visit most of the forums, not just a single language forum.
|
|
|
|
|
hi
i have some tab controls and in tab_2_enter event, i want to set focus on specifid toolStripTextBox and selectAll method, but in runTime, when i
enter to tab_2, toolStripTextBox does not selected, how to solve my problem ?
thanks
|
|
|
|
|
You can use the focus() method of the control that you want to focus.
|
|
|
|
|
i done your suggestion but don't get result
|
|
|
|