Design a class using Inheritance

S

sk.rasheedfarhan

Hi ,
I am using C#
I am having 4 classes. like below.
public class A
{
String m_strRuleName;
String m_strRuleGuid;
// Some member functions.
public Object NextItem;
}

In public class B
{
String m_strCategoryName;
String m_strCategoryGuid;
// Some member functions.
public Object NextItem;
}

In public class C
{
String m_strPackName;
String m_strPackGuid;
// Some member functions.
public Object NextItem;
}

My problem is,
Step 1)Can I use the reusability concept here by declaring
the member variable in only one class and using for rest of the class
also.
Like public class A
{
String m_strName;
String m_strGuid;
public Object NextItem;
}

public class B
{
// Some member functions.
public Object NextItem;
}
etc....

Step 2) I am using list of objects for each class [A,B,C]. So when
I will retrieving data of each class, I have to get the data.

Now I am doing individually by creating list of objects of each class
[with its member variable and member functions ] and getting the data
from a loop. [for this I am using Linked list conecpt].

But I have to use Reusability concepts in my program so please any body
help out.
can we create a class like step1 and step2, if such so please tell me,
wat i need to do.

Regards,
Rs.
 
P

Peter Bradley

There are loads of ways of doing this. If I understand your problem, here's
what I would look at for starters:

First I'd create an abstract class. Let's call it a "Thingy". This class
would have two string properties (for the Name and the Guid) and a Thingy
property for the NextItem). I don't see why the NextItem variable should be
of type Object. Your list is going to be of Thingies, if I understand you
correctly.

I'd also provide appropriate getters and setters for the properties. All of
them would presumably have getters. Only you know which of them needs
setters.

Then I'd provide abstract methods for all the methods the various concrete
classes will share with the abstract class.

Next, I'd create a RuleThingy class, a CategoryThingy class and a PackThingy
class - all inheriting from the abstract base class Thingy. They would add
any extra instance variables and properties that they needed, and would
instantiate the abstract methods in a way that suits them, as well as
providing any methods of their own that they required.

You can now create linked lists to your heart's content. You can either
create lists that only hold one type of Thingy, or you can create lists that
can hold any type of Thingy, using reflection, or some other technique, to
find out which type, precisely, you have when you extract or read an item
from the list.

Of course, doing all this linked list stuff is just reinventing the wheel,
because C# provides loads of perfectly adequate list classes ready-made for
you. However, I suspect that this is a college exercise, so this is all I'm
going to say. You'll have to work the rest of it - and the problems in this
particular way of doing things - out for yourself.

Once you have something to show that you've had a fair old try at it, but
have hit problems you can't solve, I'm sure that people will be willing to
help you again: but you'll have to show that you're not just expecting us to
do your homework for you.

:)

Peter


Hi ,
I am using C#
I am having 4 classes. like below.
public class A
{
String m_strRuleName;
String m_strRuleGuid;
// Some member functions.
public Object NextItem;
}

In public class B
{
String m_strCategoryName;
String m_strCategoryGuid;
// Some member functions.
public Object NextItem;
}

In public class C
{
String m_strPackName;
String m_strPackGuid;
// Some member functions.
public Object NextItem;
}

My problem is,
Step 1)Can I use the reusability concept here by declaring
the member variable in only one class and using for rest of the class
also.
Like public class A
{
String m_strName;
String m_strGuid;
public Object NextItem;
}

public class B
{
// Some member functions.
public Object NextItem;
}
etc....

Step 2) I am using list of objects for each class [A,B,C]. So when
I will retrieving data of each class, I have to get the data.

Now I am doing individually by creating list of objects of each class
[with its member variable and member functions ] and getting the data
from a loop. [for this I am using Linked list conecpt].

But I have to use Reusability concepts in my program so please any body
help out.
can we create a class like step1 and step2, if such so please tell me,
wat i need to do.

Regards,
Rs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top