Thread: The Principal Of Least Priviliged ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    719

    The Principal Of Least Priviliged ?

    I find myself having a hard time deciding when and how to use member functions within a class.

    Situation A:
    i have a private member 'int x', and a method setX(int n){ x = n; }.
    within a private member 'do_something(void)' i need to change the value of x...do i use setX() or simply x = a_number; ?


    Situation B: (this will make more since after looking at the code)
    i have a class which evaluates regular expressions.
    i have a private member 'vector<int> regex' and a constructor
    'myclass(const string &)'. a private method 'convert(const string &)' which converts a string into a vector of integers. there is another private member called 'makeValid(???)' which ensures a regular expression is valid by adding various characters to it. (ex: closing a group with ')' ) ...and then another private method which is called 'prepare(const string &)'

    should i pass regex into these functions and then return regex?
    like so
    Code:
    myclass::myclass(void){ prepare(); }
    void myclass::prepare(const string &source)
    {
    	regex = convert(source);
    	regex = makeValid(regex);
            //theres quite a few more function that will manipulate
            //regex the same way makeValid does
    }
    or just let the methods take care of it

    Code:
    myclass::myclass(void){ prepare(); }
    void myclass::prepare(const string &source)
    {
    	convert(source);                     //accesses regex directly
    	makeValid(void);                 //ditto
            //theres quite a few more function that will manipulate
            //regex the same way makeValid does
    }
    i know this seems like a trivial question, but all my classes eventually turn into spaghetti no matter how i implement them
    Last edited by misplaced; 12-16-2004 at 07:28 AM.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie to C++ needs help plz!!
    By xuder in forum C++ Programming
    Replies: 11
    Last Post: 01-23-2008, 08:36 AM
  2. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  3. Principal of least privilege
    By carlin70 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2003, 08:15 PM
  4. Loan calculation formula
    By C++Nerd in forum C++ Programming
    Replies: 1
    Last Post: 10-06-2002, 12:57 PM