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

How to create exclusive classes?

I have the following Methods:

public SecondResult DoSomething()
{
FirstResult firstResult=GetFirstResult();
SecondResult secondResult=GetSecondResult(firstResult);
return secondResult;
}

private FirstResult GetFirstResult()
{...}

private SecondResult(FirstResult fr)
{...}

The Method GetSecondResult should only and only then be called after
GetFirstResult has been called. To achieve that I want that the only way to
obtain a SecondResult object is through calling the FirstResult method.

This compares to the IOrderedEnumerable<Ttype that is returned from the
OrderBy and OrderByDescending(IEnumerable<T>) methods, so that it is ensured
that the ThenBy and ThenByDescending(IOrderedEnumerable<T>) methods can only
be used after application of a OrderBy method.

How do I achieve this?
Nov 13 '08 #1
3 1860
On Thu, 13 Nov 2008 00:10:00 -0800, DabblerNL <Da*****@communty.nospam>
wrote:
I have the following Methods:

public SecondResult DoSomething()
{
FirstResult firstResult=GetFirstResult();
SecondResult secondResult=GetSecondResult(firstResult);
return secondResult;
}

private FirstResult GetFirstResult()
{...}

private SecondResult(FirstResult fr)
{...}

The Method GetSecondResult should only and only then be called after
GetFirstResult has been called. To achieve that I want that the only way
to
obtain a SecondResult object is through calling the FirstResult method.

[...]
How do I achieve this?
What problem are you having? The above seems reasonably straightforward.
What specific question do you have?

By the way, rather than having two methods in the same class, one which
operates on the instantiated class (i.e. "FirstResult"), it might make
sense for the second method to actually be an instance method of the
instantiated class. Functionally it would be basically the same,
depending on how you construct the class "FirstResult", but it may provide
better encapsulation of your intermediate results (I can't say for sure,
because there are so few actual details in your proposal...but I think it
probably would).

Pete
Nov 13 '08 #2
Hello Pete,

Thanks for you answer. I am not having a problem really. My code works fine.
I am just exploring different programming techniques.
What I want is to create code that ensures that some methods can only be
called after some other methods have been called first, because these
previous methods assing some values to the properties of the class that the
later methods work on.

The .Net Methods OrderBy and ThenBy do exactly that.: ThenBy works on a
IOrderedEnumerable<T>, which is the return value of the OrderBy Method. As
far as I know there is no other way to create a IOrderedEnumerable<Tthan
vby using OrderBy. I like that approach but are wondering how it is done.

I will try your suggestion of moving the GetSecondResult Method to the
FirstResult class. It will not make the code necessarily more readible though.

My real code is:

public List<SeatingSeatCellList(List<Cellcells)
{
cells.Seat();//will set some properties in the cells in the List
return AdaptToSeatingList(cells);//reads the properties that are change
and makes a List<Seating>
}

private List<SeatingAdaptToSeatingList(List<Cellcells)
{
var result=new List<Seating>
// do some work on the cells
return result;
}

As you see the AdaptToSeatingList Method accepts a List<Cellbut it
requiers that some properties of the elements of this list are assigned to.
This can be solved by doing some error checking inside the AdaptToSeatingList
method, but this is ugly. I would rather have the Seat() (extension) method
of the List<Cellreturn a List<SeatedCellsand have the AdaptToSeatingList
method accept this type as an argument. This is not difficult to achieve, but
I would like to ensure that the only way to get a List<SeatedCellsis
through the List<Cell>.Seat() method.
How??
"Peter Duniho" wrote:
On Thu, 13 Nov 2008 00:10:00 -0800, DabblerNL <Da*****@communty.nospam>
wrote:
I have the following Methods:

public SecondResult DoSomething()
{
FirstResult firstResult=GetFirstResult();
SecondResult secondResult=GetSecondResult(firstResult);
return secondResult;
}

private FirstResult GetFirstResult()
{...}

private SecondResult(FirstResult fr)
{...}

The Method GetSecondResult should only and only then be called after
GetFirstResult has been called. To achieve that I want that the only way
to
obtain a SecondResult object is through calling the FirstResult method.

[...]
How do I achieve this?

What problem are you having? The above seems reasonably straightforward.
What specific question do you have?

By the way, rather than having two methods in the same class, one which
operates on the instantiated class (i.e. "FirstResult"), it might make
sense for the second method to actually be an instance method of the
instantiated class. Functionally it would be basically the same,
depending on how you construct the class "FirstResult", but it may provide
better encapsulation of your intermediate results (I can't say for sure,
because there are so few actual details in your proposal...but I think it
probably would).

Pete
Nov 13 '08 #3
On Thu, 13 Nov 2008 06:43:01 -0800, DabblerNL <an**@newsgroup.nospam>
wrote:
[...]
The .Net Methods OrderBy and ThenBy do exactly that.: ThenBy works on a
IOrderedEnumerable<T>, which is the return value of the OrderBy Method.
As
far as I know there is no other way to create a IOrderedEnumerable<T>
than
vby using OrderBy. I like that approach but are wondering how it is done.
There's nothing magic about it. In fact, it's not true that "there is no
other way to create an IOrderedEnumerable<TElement>". You can implement
the interface yourself if you like, and pass an instance of that
implementation to the methods that take it. As long as your
implementation behaves correctly, then everything will work fine. But, if
your implementation does not, there's nothing in LINQ that can enforce
that and ensure correct behavior in spite of it.
[...] I would rather have the Seat() (extension) method
of the List<Cellreturn a List<SeatedCellsand have the
AdaptToSeatingList
method accept this type as an argument. This is not difficult to
achieve, but
I would like to ensure that the only way to get a List<SeatedCellsis
through the List<Cell>.Seat() method.
How??
What you're asking for is not literally possible. Any code that knows the
SeatedCells type can create a List<SeatedCells>.

You can limit the opportunity for other code to do that by making the type
private nested within your outer class (and it's possible that would be a
good idea anyway, if all of this logic is private to the outer class), but
that won't stop code from within your outer class from misusing the type.

But note that this isn't really like the code you originally posted. In
particular, the type being passed around isn't your own type, but rather a
public type containing your own type. If the type being passed around was
in fact your own type, then you could provide better guarantees, by
putting the logic required to apply whatever state you want into the
constructor itself. That would make it impossible to get an instance of
that type without initializing it in just the way you want.

So, one approach you might do is wrap the List<Cellsinside a type of
your own making. For it to be truly protected, you would have to copy in
the original List<Cells>, otherwise some caller could potentially modify
the List<Cellspassed to the constructor after the fact. Your wrapper
class could contain the implementation of your "AdaptToSeatingList()"
method, or the wrapper class could provide whatever access to the list is
required by the "AdaptToSeatingList()" method (e.g. you could implement
the IList<Cellsinterface, and then have the "AdaptToSeatingList()"
method work on an IList<Cells>, rather than the specific List<Cells>).

Pete
Nov 13 '08 #4

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

Similar topics

0
by: Paul Munly | last post by:
Hi, I'm attempting to get a Swing application to go into Exclusive Fullscreen mode and am curious if there's something that I need to do prior to attempting to grab the fullscreen window. The...
1
by: Chuck Van Den Corput | last post by:
I have encountered a problem that I am hoping someone can shed some light on. I have a multi-user A97 app. All users have a personal front-end MDE accessing a shared back-end. There is no...
0
by: Wayne | last post by:
Can someone please help with this problem. When referring to opening a database in Exclusive mode the Access 2003 help says: "Under Default open mode, do one of the following: If you want others...
1
by: JohnC | last post by:
I have this exact same scenario. It is new and seems to be related to when we installed Adobe 7.0 Standard/Professional. We have an MDB on a LAN file server. Using Access 2K and Windows 2K. ...
1
by: University of Toronto | last post by:
Hi gang, Hopefully someone can help us out. In short - Access 2002, db split into a front end and back end. It appears that our backend db is locked. Our form bound to one table won't allow...
18
by: Andre Laplume via AccessMonster.com | last post by:
I have inherited a bunch of dbs which are are shared among a small group in my dept. We typically use the dbs to write queries to extract data, usually dumping it into Excel. Most dbs originated...
17
by: teddysnips | last post by:
One of my clients has asked me to make a change to one of their Access applications. The application is a Front End/Back End standard app. I didn't develop it, but looking at it tells me that...
2
by: sebastien.abeille | last post by:
Hello, I would like to create a minimalist file browser using pyGTK. Having read lot of tutorials, it seems to me that that in my case, the best solution is to have a gtk.TreeStore containing...
3
by: Arun Srinivasan | last post by:
Please correct me if I am wrong 1. no 2 processes can have exclusive lock on same object (by object, same row or same table) 2. on deadlock incident between 2 processes only one of them will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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
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,...

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.