Re: How much oop is too much oop?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Doug Harrison [MVP] wrote:

> That's kinda what I was getting at. :) When I think "invalid" in this
> context, I envision something like:
>
> struct X
> {
> int m_x;
> };
>
> X x;
> // Here, x is invalid, uninitialized, or whatever you want to call it.

[...]

> CWnd is not like X. Rather, its ctor puts it into a good state,
> albeit one with very limited capabilities. In particular, it passes
> the AssertValid test.

Not at all. Object x has a perfectly well defined state in which the only
method you can call on it is the destructor or assignment to field m_x. It
is no different from an "unhooked" CWnd were there are some mthods you can
call and some that you cannot. Both cases are evil. When an object has
multiple states one should either use some variation of state pattern or
decompose it in two (or more) classes.

> I'm not sure exactly what a two-class approach buys you over a single
> class with two-phase construction.

1) RAII
2) No special/singular/invalid ( pick your term ;-) ) states

--
Eugene
http://www.gershnik.com


.



Relevant Pages

  • Re: Error in Accept
    ... My server program shows "Invalid argument" in connectcall. ... int sid,sockfd,sin_size,new_fd,n; ... struct sockaddr_in their_addr; ... bind() doesn't return a socket-fd ... ...
    (comp.unix.programmer)
  • Re: Alignment of foo[1][1][1][1]
    ... I believe it would be a violation of the effective type rules. ... struct B {int b; int c;}; ... array types, so if the above is invalid, the array equivalent must be ...
    (comp.lang.c)
  • Re: 2D array with different column types / Dumbass can figure out segfault
    ... where each column is of a different type, say an int and a struct*? ... test.c:34: error: invalid use of void expression ...
    (comp.lang.c)
  • Re: returning lvalue in C vs C++
    ... struct thing t =; ... int y = = t).x; ... This is invalid in both C and C++. ... thanks for the detailed explanation. ...
    (comp.programming)
  • Re: how to create cwnd in cappthread
    ... I then get a debug assertion error in the CWnd class: ... BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, ...
    (microsoft.public.vc.mfc)