473,809 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create exclusive classes?

I have the following Methods:

public SecondResult DoSomething()
{
FirstResult firstResult=Get FirstResult();
SecondResult secondResult=Ge tSecondResult(f irstResult);
return secondResult;
}

private FirstResult GetFirstResult( )
{...}

private SecondResult(Fi rstResult 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 IOrderedEnumera ble<Ttype that is returned from the
OrderBy and OrderByDescendi ng(IEnumerable< T>) methods, so that it is ensured
that the ThenBy and ThenByDescendin g(IOrderedEnume rable<T>) methods can only
be used after application of a OrderBy method.

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

public SecondResult DoSomething()
{
FirstResult firstResult=Get FirstResult();
SecondResult secondResult=Ge tSecondResult(f irstResult);
return secondResult;
}

private FirstResult GetFirstResult( )
{...}

private SecondResult(Fi rstResult 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. "FirstResul t"), 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 "FirstResul t", 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
IOrderedEnumera ble<T>, which is the return value of the OrderBy Method. As
far as I know there is no other way to create a IOrderedEnumera ble<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<SeatingSea tCellList(List< Cellcells)
{
cells.Seat();//will set some properties in the cells in the List
return AdaptToSeatingL ist(cells);//reads the properties that are change
and makes a List<Seating>
}

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

As you see the AdaptToSeatingL ist 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 AdaptToSeatingL ist
method, but this is ugly. I would rather have the Seat() (extension) method
of the List<Cellreturn a List<SeatedCell sand have the AdaptToSeatingL ist
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<SeatedCell sis
through the List<Cell>.Seat () method.
How??
"Peter Duniho" wrote:
On Thu, 13 Nov 2008 00:10:00 -0800, DabblerNL <Da*****@commun ty.nospam>
wrote:
I have the following Methods:

public SecondResult DoSomething()
{
FirstResult firstResult=Get FirstResult();
SecondResult secondResult=Ge tSecondResult(f irstResult);
return secondResult;
}

private FirstResult GetFirstResult( )
{...}

private SecondResult(Fi rstResult 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. "FirstResul t"), 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 "FirstResul t", 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
IOrderedEnumera ble<T>, which is the return value of the OrderBy Method.
As
far as I know there is no other way to create a IOrderedEnumera ble<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 IOrderedEnumera ble<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<SeatedCell sand have the
AdaptToSeatingL ist
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<SeatedCell sis
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<SeatedCell s>.

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<Cellsinsid e 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<Cellspasse d to the constructor after the fact. Your wrapper
class could contain the implementation of your "AdaptToSeating List()"
method, or the wrapper class could provide whatever access to the list is
required by the "AdaptToSeating List()" method (e.g. you could implement
the IList<Cellsinte rface, and then have the "AdaptToSeating List()"
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
3101
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 code in question follows: <code> this.setUndecorated(true); GraphicsDevice gd = this.getGraphicsConfiguration().getDevice(); if(gd.isFullScreenSupported()) {
1
3263
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 specific MDW file for the app as security rules are housed within the app itself. On a couple of occasions, different users have launched the app only
0
1993
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 to be able to open the Microsoft Access database at the same time you have it open, click Shared. If you want sole access to the Access database when you have it open, click Exclusive." >From my experience and from what I have read on the...
1
3926
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. When the application is opened by someone, it seems that if one of the Adobe 7.0 (Standard or Professional) users susequently open the application, they get the error - "...You do not have exclusive permissions to the database. Changes that you...
1
2481
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 new records to be created. When I open the table up directly, attempts at a new record result in an error stating that the table is locked by a user (me) who has opened the database in exclusive mode (from my computer). The problem is that I do...
18
7348
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 in MsAccess 97 or prior and have been converted to 2003. On occassion user 1 will open a db. When user 2 opens the db it will not let user 2 modify macros and what not. I can understand this and realize we could split the db; it is not worth ...
17
3926
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 it was done entirely using the Wizards. There is no log-in procedure. They want to amend it so that only one person can be logged in at any one time. So, if Joe Bloggs tries to open the application, and Fred Jones has already connected, Joe...
2
2407
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 all the files and folders so that it would map the file system hierarchy.
3
2778
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 cancelled by db2 to let the other finish. Now, can there be an instance where 2 processes have 'EXCLUSIVE LOCK' on same table, and are waiting on the same 'EXCLUSIVE LOCK' held by the other agent to be relinquished. They both are cancelled by db2...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10387
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.