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

Multi level class implementation

What is the correct way to implement this real world problem?

Planning Process:
----------------------------------------------------------
--+ Plan: (name, GetCost, GetPaidAmount)
----+ Activities: The plan has many activities (name, GetCost,
GetPaidAmount)
------+ Budget Items: again each activity has many budget item. (name,
smallCost)
--------+ Payment: There is more than one payment for each Budget Items
(month,amount)

Use case:
If we plan for 12 months (1-12) then the payment can be made again the
budget item within any month from 1 -12.

I feel this problem can be implement in C# in OOP way.
But when I try I was get lost.
I am not sure to to related each class to gether.

Please advise me with some implementation prototype.
Many thanks
Nov 16 '05 #1
3 1535

"kids_pro" wrote...
What is the correct way to implement
this real world problem?
[snip]

There are *many* correct ways, but probably also many *incorrect* ways...

It all really depends on how these classes then are supposed to *work
together*, so...
I feel this problem can be implement in C# in OOP way.
....before you go further on OOP, you should try some OOA&D (analysis and
design), to check what requirements the classes have for each other.
Use case:
If we plan for 12 months (1-12) then the
payment can be made again the
budget item within any month from 1 -12.


Well, that's a "use case" only at a brief level...

You need to know also what is expected as *outcome* of the system, and then
work your way backwards...

If you know anything about UML, you can e.g. use sequence diagrams, to model
this behavior, and from that much of the design of the classes will emerge.

// Bjorn A
Nov 16 '05 #2
Bjorn,

Thank for your input I have attach a sample code that I try to implement.
(I know I am still beginner in OOP) but please let me know how is my
implementation.

Regards,

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:uw*************@TK2MSFTNGP10.phx.gbl...

"kids_pro" wrote...
What is the correct way to implement
this real world problem?
[snip]

There are *many* correct ways, but probably also many *incorrect* ways...

It all really depends on how these classes then are supposed to *work
together*, so...
I feel this problem can be implement in C# in OOP way.


...before you go further on OOP, you should try some OOA&D (analysis and
design), to check what requirements the classes have for each other.
Use case:
If we plan for 12 months (1-12) then the
payment can be made again the
budget item within any month from 1 -12.


Well, that's a "use case" only at a brief level...

You need to know also what is expected as *outcome* of the system, and

then work your way backwards...

If you know anything about UML, you can e.g. use sequence diagrams, to model this behavior, and from that much of the design of the classes will emerge.
// Bjorn A



Nov 16 '05 #3

"kids_pro" wrote...
I have attach a sample code that I try to implement.
(I know I am still beginner in OOP) but please let
me know how is my implementation.


Well, it's a start...

You'll probably need some collection to keep track of the activities within
a Plan (and likewise for budgets in Activities, etc).

If an Activity really needs to know its Plan is one of the questions that
only can be answered when you get further with the OOA&D (e.g. through
sequence diagrams). If it does, you'll have a bidirectional association
between Activity and Plan, which always is more difficult to maintain than a
unidirectional association.

I'll just give some examples on improvements that *can* be made on your
present code, but even those can be questioned, as one has to know more
about how these classes will be used in *practice*, i.e. within an
application.

I have in the example focused only on the *relation* between Plan and
Activity, the rest is up to you... :-)

================================================== =====

using System;
using System.Collections;

namespace ConsoleApplication1
{
// To facilitate the possibility to enumerate through
// the activities within the Plan, we can implement
// IEnumerable

public class Plan : IEnumerable
{
string name;
int nMonth;

// We need some collection for our activities.
// Whether it's to be a Hashtable, an ArrayList,
// or another type, is to be answered of the
// analysis and design

Hashtable activities = new Hashtable();

public Plan(string planName, int nmonth)
{
this.name = planName;
this.nMonth = nmonth;
}

public int NumberOfMonth
{
get{return nMonth;}
set{nMonth = value;}
}

public string Name
{
get{return name;}
set{name = value;}
}

// Now, here's really a big question!
// If an activity is created "outside" the Plan,
// there's the possibility that it can end up in
// another Plan as well...

// public void AddActivity(Activity newAct) { }

// ...so I suggest another approach...

public void CreateActivity(string actName, int cost)
{
Activity a = new Activity(this, actName, cost);
activities.Add(actName, a);
}

// To get hold of a specific Activity within the
// plan, we can use an indexer...

public Activity this[string actName]
{
get { return (Activity) activities[actName]; }
}

// As we wanted to be able to iterate
// through the activites (e.g. with foreach)
// we simply borrow the one from our
// collection...

public IEnumerator GetEnumerator()
{
return activities.Values.GetEnumerator();
}
}

public class Activity
{
string name;
int cost;

// It's good practice to be consequential
// when naming fields.

Plan masterPlan;

public Activity(Plan mp, string actName, int cost)
{
this.masterPlan = mp;
this.name = actName;
this.cost = cost;
}
}
}

=====================================
Happy coding! :-)

// Bjorn A

Nov 16 '05 #4

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

Similar topics

1
by: Stephen Thorne | last post by:
Decorators have been getting lots of air-time at the moment, but only really the syntax. After a short discussion on irc the other night I decided to download python2.4 from experimental and write...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
3
by: Amit | last post by:
Greetings All. One of the usages that I need is accessing the contents of the container that I am using in level order( which would mean breadth- first search approach for a binary tree) as...
1
by: Tim Marshall | last post by:
A2003. I am getting this error message when I try to set a report's recordsource to an SQL statement or a saved querydef that uses sub-queries. I've debug.printed the SQL, and run it as a stand...
4
by: snowweb | last post by:
I am trying to implement a CSS hierarchical unfolding menu on a site. The thing is, it needs to be dynamically populated from the results of a database query. I previously had the menu working but...
14
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I just started learning Threading in C#. I read lot of articles and what I am trying to accomplish here is that I have an array of string and I want to pass the member of that...
4
by: Joseph Paterson | last post by:
Hi all, I'm having some trouble with the following code (simplified to show the problem) class Counter { protected: int m_counter; }
6
by: python | last post by:
I need to generate multi-level incrementing labels for an outline/hierarchy where the string for each level of a label is based on an incrementing sequence like 1, 2, 3 or A, B, C, or even I, II,...
6
TheServant
by: TheServant | last post by:
Hi all, I am trying to make a multi-level menu for my site, however all of the info comes from the database. In the database (which I can change if there is a better structure) there is a bit more,...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.