473,396 Members | 1,967 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,396 software developers and data experts.

abstract class used as a parameter in a function.

The program calls for an abstract base class (used in two additional functions). No problems here.
The final part is to create a function that accepts the base class as a parameter: static void getStats() that accepts a parameter of type Account (see below). It is to display the data from Inquiry.

Expand|Select|Wrap|Line Numbers
  1. abstract class Account
  2. {
  3.  ...
  4.  public virtual double Inquiry()
  5.   {
  6.    ...
  7.   }
  8. }
  9. class checkingAccount : Account
  10. {
  11.  ...
  12. }
  13. class savingsAccount : Account
  14. {
  15.  ...
  16. }
  17.  
I can't seem to find any documentation on how to pass an abstract type as a parameter. And then I have to figure out which account I'm passing to get the right inquiry results.

Point me in the right direction, either a quick piece of code or a good literature source.
Thanks
D
Sep 2 '10 #1

✓ answered by hype261

This is what you are looking for.

static void getStats(Account account)
{
}

The good thing is that you can pass either a checking account or savings account into the getStats method.

4 6705
hype261
207 100+
This is what you are looking for.

static void getStats(Account account)
{
}

The good thing is that you can pass either a checking account or savings account into the getStats method.
Sep 2 '10 #2
Thanks for the help.
I was really overthinking the problem.
Sep 2 '10 #3
hype261
207 100+
David,

I missed this statement in your original post and I felt it needed correcting.

Quote...
And then I have to figure out which account I'm passing to get the right inquiry results.

If you have to figure out which type of account you are passing to a method it generally means that something is messed up in your design.

The benefit of virtual methods is that you don't have to figure out which account type is being used. If both the savings and checking account override the Inquiry method then when you pass either to the getStatus method the appropriate Inquiry method will be called. The is one of the main advantages of an OO language.
Sep 2 '10 #4
As I said before, I was really overthinking the problem. Once I saw your code snippet it was like having a bucket of cold water thrown on my face. Wake-up time.
I have the entire program running and am now in the process of trying to find anything that will break it.
Sep 2 '10 #5

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

Similar topics

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?)...
4
by: WittyGuy | last post by:
Hi all, Though I know the concepts of both abstract class & virtual function (like derived class pointer pointing to base class...then calling the function with the pointer...), what is the real...
3
by: Jeff | last post by:
I have an abstract class which uses System.Windows.Forms.UserControl as it's base class. It has some custom drawing methods and it also handles a few common events like Paint, PaintBackGround,...
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...
4
by: hazz | last post by:
public abstract class FormShellApplication<TWorkItem, TShell> : WindowsFormsApplication<TWorkItem, TShell> where TWorkItem : WorkItem, new() where TShell : Form thank you, -hazz
9
by: silversurfer2025 | last post by:
Hello everyone, I am currently having problems with a C++ abstract class. I have a class FrameWork.h which defines some methods (of which some are abstract, i.e. virtual void method() = 0). In...
2
by: pinki panda | last post by:
i want to knw the diff between static class and abstract class .i would appreciate if its followed by example
21
by: Mr.SpOOn | last post by:
Hi, I'm going to work on a project to represent some musical theory in Python, in an object oriented way. I have to manage many elements of music such as notes, intervals, scales, chords and so...
4
by: Pranav | last post by:
Hello All, I have a simple question regarding the definition of abstract class, IIRC , Abstract class is one which contains virtual function declaration and other variables and no object of this...
4
by: dascandy | last post by:
Hi, For a project I'm working on I'm kind-of-hacking my way around deriving a class from an interface or such to create a mock, but instead creating the mock directly. It is usable as the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.