Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2004, 04:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default Theory to Practise Problems

Hi all,
I am trying to get my head arround the classes and inheritance.
I understand the thoery quite well I beleive but I am having trouble getting the structure of the code straight in my head.

I have a class named Person, and a class named User which inherits the Person class.

In my working example i wish to log the user in.

To do this I had planned on making the User constructor take the log in details, Username and Password.

My intension was the same for the Person to a point, the personID would be passed to the constructor.

My question is how do I run the two constructors to create a complete user with all the attributes of a person?

Or should I be looking at this all together differently?

PS.
I did not wish to have a set accessor to the PersonID or UserID. Which started my problems as I don't now how to set the PersonID varaible form the User class



======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old July 27th, 2004, 07:39 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to krishnabhargav
Default

My idea is to write overloaded constructors in User.
public User(string name,string pwd)
{
//your code
}
public User(string name,string pwd,int perrsonid) : base(personid)
{
//your code
}

Everybody is talented but i am intelligent enough to learn from their knowledge.
 
Old July 27th, 2004, 08:40 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think your mean is getting all(or necessary)fields from your parent class
and giving them to your child class
------------
//C#
class Parent
//declare all(or necessary)fields for childs as public(or protected)
public int necessaryForAll;
protected int necessaryForChilds;
private int unnecessaryForOtherClasses;
//your constructer
public Parent(,,,)//could have more parameters
{
//initialize all the fields if you forget some of them compiler gives them the default value(null for classes,0 for integers,.....)
}
//now Derivation
Class Child:Parent
{
//Declare the new necessary fields in addition to-
//your fileds (public or protected) in Parent class
//***IMPORTANT...Then you should exactly call
//the constructer with the same parameters as parameters in your parent
//constructor *****Because here you want to load the necessary fields of
//your parent class in addittion the fields of your child class******
public child:base(,,,)
{
//initialize all new fields declared in your child class
}
-------------------
Hope This could help you.

--------------------------------------------
Mehdi.
 
Old July 27th, 2004, 08:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Thank you both, I'll try out these ideas.

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
divs inside divs: theory? Giant_robot_sandwich CSS Cascading Style Sheets 11 September 13th, 2006 03:56 PM
Content Management Theory rit01 SQL Server ASP 0 November 30th, 2005 05:39 AM
validate.asp problems and logon.asp problems p2ptolu Classic ASP Databases 0 February 16th, 2005 02:34 PM
Best Practise for VS.NET IDE and Classic ASP rodmcleay Classic ASP Professional 1 September 3rd, 2004 03:12 PM
Two Problems goraya C# 2 May 21st, 2004 05:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.