473,809 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

proper OO way

Hi,
classTeacher contains a list of classChild
ClassChild contains methods, props and so on
Most things a classChild can do on its own.
But AskPermission cannot be done by the Child, but must be done by the
teacher.
Child has to ask its teacher to do that.
Is it a proper OO way to have a reference to the teacher to call a
teachermethod?
Thanks
Frank
Nov 17 '05 #1
1 1059
Frank wrote:
classTeacher contains a list of classChild
ClassChild contains methods, props and so on
Most things a classChild can do on its own.
But AskPermission cannot be done by the Child, but must be done by the
teacher.
Child has to ask its teacher to do that.
Is it a proper OO way to have a reference to the teacher to call a
teachermethod?


Simple solution would be to pass a pointer of a Teacher to every Child
during construction/initialization.

Pure solution would be to have abstract class "PermissionGran ter" that
Teacher should inherit, so that children should have a pointer of that
class instead of class Teacher.

Complex solution would be for all children to have a pointer to
"PermissionDisp atcher" that will call a function of an appropriate
PermissionGrant er according to the Child's properties, current time of
day, or whatever.

In all cases every Child should have some kind of pointer so that it
actually can AskPermission. You should always keep things as simple as
possible, so I recommend the simple solution. Since the Teacher contains
the list of children the complex solution doesn't make sense anyway.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3686
by: Kevin | last post by:
I am currently importing data into Access 2002 from 3 Sybase ASA 7.0 databases over a network. At this time I am using a ODBC System DSN connection using the proper ASA 7 driver. I would like to be able to make a DSN-Less connection so that my software is not dependent on having ODBC set-up with proper drivers and information. I have done hours of searching/testing but have been unsuccessful at making a DSN-Less connection. Could...
1
2135
by: RC | last post by:
I have an Access 2002 database with many tables and forms (but just to keep things simple, let's say the DB has one Table "Table1" and one Form "Form1"). I have managed to cobble together so much complex code to add records and edit records I need to step back and ask you all what is the proper way to do this. The database is DAO. The table has Columns SerialNumber, CPU, HardDrive and Model. I am trying to use a Form to fill out the...
0
1380
by: bj | last post by:
hello is there any chance to get proper char width for class derived from user control - im working over text editing control, so i need proper width of every character for currently selected font, in my example i bind parent font and i use Api function GetCharWidth to get characters width, this function working fine for mfc however values returning for C# control looks bigger than actual character pixel width for that control, the...
0
1282
by: yogarajan | last post by:
hi all i need proper alignment my treeview looks like <checkbox>Fruits(parent)-134 <checkbox>Mango(child)-45 <checkbox>Orange(child)-45 <checkbox>Apple(child)-34 <checkbox>Car(parent)-223
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.