Thread: Assert: When to and when not to.

  1. #16
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Well here's the thing, I think.

    If I take edit out of employee, then some other system needs to have edit.

    And if another system needs to have edit, it needs to know how to edit whatever we give it (what if it's not an employee?)

    I could use polymorphism and create a class called database_object, and virtualize member functions like edit.

    I can't think of a real clean way to handle the edit function being in another class. Ultimately I would want that system to handle more than just an employee object.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Just make it a free function that takes a reference to the employee to modify. By overloading the edit function, you can easily have a single function that can edit all different types of objects without being coupled to the object it modifies.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    I would have to relearn how to overload functions D:

    could you give me an easy example?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    void bar(foo1& a);
    void bar(foo2& b);
    void bar(foo3& c);
    //and so on

    Same function name, and different parameter list. May also have different return types, but must have a different parameter list.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Ohhh, I see.

    Would it be a bad idea to overload an edit function that is in a class called interface?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Without knowing how that class looks like and what it does, it is impossible to say.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    I think I'm getting ahead of myself, I need to simply streamline my functions for managing a vector of employees. I can't worry about making a generic object database that is super ooped up and all re-usable yet.

    I need more working code first lol.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  8. #23
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It's about the separation of concerns. A class that is concerned with storing employee data - should it really be concerned with user interaction as well? What if your system changes from a console interface to a GUI?

    If you want an ConsoleUI::edit() operation that can deal with any kind of database_object, that's what the Visitor Pattern is for.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assert/Macro
    By tempster09 in forum C Programming
    Replies: 15
    Last Post: 12-17-2009, 10:13 PM
  2. assert
    By George2 in forum C Programming
    Replies: 1
    Last Post: 10-22-2007, 03:17 AM
  3. Assert
    By Shamino in forum C++ Programming
    Replies: 8
    Last Post: 01-24-2006, 11:02 AM
  4. How to use assert?
    By jjbuchan in forum C Programming
    Replies: 2
    Last Post: 11-11-2005, 01:40 PM
  5. assert
    By ammar in forum C++ Programming
    Replies: 1
    Last Post: 10-19-2002, 08:17 AM