Click here to Skip to main content
15,924,482 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How about a constructor that autodestructs? Pin
Colin Angus Mackay23-Jul-06 20:15
Colin Angus Mackay23-Jul-06 20:15 
GeneralRe: How about a constructor that autodestructs? Pin
Giancarlo Trevisan23-Jul-06 20:22
Giancarlo Trevisan23-Jul-06 20:22 
GeneralRe: How about a constructor that autodestructs? Pin
Guffa23-Jul-06 22:44
Guffa23-Jul-06 22:44 
GeneralRe: How about a constructor that autodestructs? Pin
Giancarlo Trevisan24-Jul-06 2:05
Giancarlo Trevisan24-Jul-06 2:05 
GeneralRe: How about a constructor that autodestructs? [modified] Pin
Dave Kreskowiak24-Jul-06 2:38
mveDave Kreskowiak24-Jul-06 2:38 
GeneralRe: How about a constructor that autodestructs? [modified] Pin
Giancarlo Trevisan24-Jul-06 2:57
Giancarlo Trevisan24-Jul-06 2:57 
GeneralRe: How about a constructor that autodestructs? Pin
Dave Kreskowiak24-Jul-06 6:44
mveDave Kreskowiak24-Jul-06 6:44 
GeneralRe: How about a constructor that autodestructs? [modified] Pin
Giancarlo Trevisan24-Jul-06 19:06
Giancarlo Trevisan24-Jul-06 19:06 
Dave,

as class builders we model the problem at hand, I consider modelling a wonderful art.

Dave Kreskowiak wrote:
Beyond the constructor, does the Environment have ANYTHING to do with what's inside the class?? Nope. So why should it care?


I can reply very simply: the Environment conditions the MythicalFooCreature during its life.

Dave Kreskowiak wrote:
Your class constructor now fails because it can't get what it expects, even though the code would run perfectly! Now what???


You are right! You can try to instantiate a MythicalFooCreature in a hostile Environment, it would probably not live, and the constructor would be the first to know. (Mind you, I don't mean to undermine Mono nor Linux)

Dave Kreskowiak wrote:
The class code should care NOTHING about what's going on outside of it. The class is, literally, it's own little world.


Hm, this is a rather strong assertion, we could really debate about this.

At any rate, I do not like to reinvent wheels, and if I do I'll use inheritance. My post questioned: why not have a Constructor that in some cases DOES NOT do its job, construct, but simply does nothing? What are the implications? However we model this necessity at the end the instance should not be there. So there, we create then destroy, that's when my minimalist nature came in, and I wrote the post, why not simply "cut short" from within the constructor?

I'm investigating the effect of Dispose as implied in the pseudocode below, this would solve the need at hand:

Class MythicalFooCreature<br />
  Public Sub New(temp)<br />
    If temp < 32 Then<br />
      Me.Dispose()<br />
      Throw System.Exception("Too cold")<br />
    End If<br />
  End Sub<br />
End Class


Maybe the dispose is not necessary since throwing an exception within a constructor does it automatically.

-- modified at 1:19 Tuesday 25th July, 2006
GeneralRe: How about a constructor that autodestructs? Pin
Colin Angus Mackay24-Jul-06 2:38
Colin Angus Mackay24-Jul-06 2:38 
GeneralRe: How about a constructor that autodestructs? Pin
Giancarlo Trevisan24-Jul-06 3:02
Giancarlo Trevisan24-Jul-06 3:02 
QuestionMS Word - like interface in .NET Pin
ravinamballa22-Jul-06 13:39
ravinamballa22-Jul-06 13:39 
AnswerRe: MS Word - like interface in .NET Pin
Ed.Poore22-Jul-06 21:12
Ed.Poore22-Jul-06 21:12 
GeneralRe: MS Word - like interface in .NET Pin
ravinamballa23-Jul-06 1:23
ravinamballa23-Jul-06 1:23 
Questionwindows service and unmanaged dll Pin
simon_pl22-Jul-06 12:43
simon_pl22-Jul-06 12:43 
AnswerRe: windows service and unmanaged dll Pin
Net_DNA22-Jul-06 22:43
Net_DNA22-Jul-06 22:43 
GeneralRe: windows service and unmanaged dll Pin
simon_pl23-Jul-06 2:37
simon_pl23-Jul-06 2:37 
QuestionAuto generating .sln .csproj files Pin
danielk_22-Jul-06 2:28
danielk_22-Jul-06 2:28 
AnswerRe: Auto generating .sln .csproj files Pin
Ed.Poore22-Jul-06 9:44
Ed.Poore22-Jul-06 9:44 
Questionproblem in Synchronize the database between PC and Pocket PC [modified] Pin
sgupta1622-Jul-06 1:40
sgupta1622-Jul-06 1:40 
QuestionUsing of combobox in VC++.Net Pin
Nagaraju_Focus21-Jul-06 22:28
Nagaraju_Focus21-Jul-06 22:28 
AnswerRe: Using of combobox in VC++.Net Pin
Ed.Poore22-Jul-06 9:46
Ed.Poore22-Jul-06 9:46 
GeneralRe: Using of combobox in VC++.Net Pin
Nagaraju_Focus23-Jul-06 18:34
Nagaraju_Focus23-Jul-06 18:34 
QuestionQuick Question - Events / Event Handleing Pin
Jawz-X21-Jul-06 10:38
Jawz-X21-Jul-06 10:38 
AnswerRe: Quick Question - Events / Event Handleing Pin
Rob Graham21-Jul-06 11:08
Rob Graham21-Jul-06 11:08 
GeneralRe: Quick Question - Events / Event Handleing Pin
Jawz-X22-Jul-06 10:03
Jawz-X22-Jul-06 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.