473,405 Members | 2,287 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,405 software developers and data experts.

Design a class using Inheritance

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.

Jan 24 '07 #1
1 1483
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
<sk**************@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
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.

Jan 24 '07 #2

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

Similar topics

18
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point...
8
by: Gert Van den Eynde | last post by:
Hi all, I have a question on interface design: I have a set of objects that are interlinked in the real world: object of class A needs for example for the operator() an object of class B. On...
4
by: Merlin | last post by:
Hi Imagine the following classes (A class diagram will help) BASE, A, B, C, D, E, F, G. A, B, C, D, G inherit from BASE. E, F inherit from D.
2
by: Tony Johansson | last post by:
Hello Experts!! Here we use multiple inheritance from two classes.We have a class named Person at the very top and below this class we have a Student class and an Employee class at the same...
0
by: JKJ | last post by:
I'm not an OOP guru, but I would say ". . .not necessarily" What if the base class and derived classes are internal? Then the base class has to be within the same assembly to be inherited from. ...
1
by: Josh28 | last post by:
Hi We are a group of two chaps just out of undergrad, we created a software to automate the use of Design Patterns. We have put it up at Source Forge--http://dpatoolkit.sourceforge.net/ The...
7
by: Steve | last post by:
Hi all, I'm designing my DAL layer(s) for our suite of applications and I'm designing myself in circles, it's gotten to the point where each idea just mixes me up more :) We have 3 loosely...
8
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
7
by: snewman18 | last post by:
In learning about design patterns, I've seen discussion about using inheritance when an object's relationship to another object is 'is-a' and composition when the relationship is 'has-a'. Since...
7
by: Immortal Nephi | last post by:
I have an idea how to design an object in a better way. I would like to give you my thought example. Please let me know what you think if it is best object design. Please recommend me any book...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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.