private-methods

Function privacy and unit testing Haskell

孤街浪徒 提交于 2019-12-03 02:14:40
问题 How do you deal with function visibility and unit testing in Haskell? If you export every function in a module so that the unit tests have access to them, you risk other people calling functions that should not be in the public API. I thought of using {-# LANGUAGE CPP #-} and then surrounding the exports with an #ifdef : {-# LANGUAGE CPP #-} module SomeModule #ifndef TESTING ( export1 , export2 ) #endif where Is there a better way? 回答1: The usual convention is to split your module into public

Function privacy and unit testing Haskell

别来无恙 提交于 2019-12-02 15:47:00
How do you deal with function visibility and unit testing in Haskell? If you export every function in a module so that the unit tests have access to them, you risk other people calling functions that should not be in the public API. I thought of using {-# LANGUAGE CPP #-} and then surrounding the exports with an #ifdef : {-# LANGUAGE CPP #-} module SomeModule #ifndef TESTING ( export1 , export2 ) #endif where Is there a better way? The usual convention is to split your module into public and private parts, i.e. module SomeModule.Internal where -- ... exports all private methods and then the

How to use a object whose copy constructor and copy assignment is private?

江枫思渺然 提交于 2019-12-01 08:39:24
In reading TCPL , I got a problem, as the title refered, and then 'private' class is: class Unique_handle { private: Unique_handle& operator=(const Unique_handle &rhs); Unique_handle(const Unique_handle &rhs); public: //... }; the using code is: struct Y { //... Unique_handle obj; }; and I want to execute such operations: int main() { Y y1; Y y2 = y1; } although, these code are come from TCPL, but I still can not got the solution... Can anybody help me, appreciate. As its name suggests, the Unique_handle isn't meant to be copied. Its implementation ensures it by disabling the copy constructor

Partitioning struct into private and public sections?

末鹿安然 提交于 2019-11-30 12:46:04
问题 In C++ and Java, data structures can have private , public and protected regions. I'd like to port this concept to a C language program I am writing. Are there any idioms for implementing private or protected function pointers and data fields in a C struct ? I know that C struct s are public, I'm looking for an idiom to help hide some implementation details and force users to use the public interface. Note: The language has been chosen by the shop, so I am stuck implementing Object Oriented

Partitioning struct into private and public sections?

夙愿已清 提交于 2019-11-30 03:59:39
In C++ and Java, data structures can have private , public and protected regions. I'd like to port this concept to a C language program I am writing. Are there any idioms for implementing private or protected function pointers and data fields in a C struct ? I know that C struct s are public, I'm looking for an idiom to help hide some implementation details and force users to use the public interface. Note: The language has been chosen by the shop, so I am stuck implementing Object Oriented concepts into C. Thanks. As you know, you cannot do this. However, there are idioms that will allow a

Objective-C: Should I declare private methods?

爱⌒轻易说出口 提交于 2019-11-29 10:04:18
I've been declaring private methods in class extensions, according to Best way to define private methods for a class in Objective-C . But, I just realized that, in Xcode 4, if I leave out the declaration of a private method altogether and just implement it, the app compiles and runs without warning or error. So, should I even bother declaring private methods in class extensions? Why should we have to declare methods anyway? In Java, you don't... neither in Ruby. A method definition only needs to be defined if the caller is declared before the method. For consistency I would recommend defining

How to do unit testing on private members (and methods) of C++ classes [duplicate]

青春壹個敷衍的年華 提交于 2019-11-28 22:43:14
This question already has an answer here: How do I test a private function or a class that has private methods, fields or inner classes? 50 answers I am very new to unit testing and I am a little confused. I am trying to do unit testing (using the Boost unit testing framework) on a C++ class called VariableImpl . Here are the details. class Variable { public: void UpdateStatistics (void) { // compute mean based on m_val and update m_mean; OtherClass::SendData (m_mean); m_val.clear (); } virtual void RecordData (double) = 0; protected: std::vector<double> m_val; private: double m_mean; }; class

Private method naming convention [closed]

允我心安 提交于 2019-11-28 19:08:41
Is there a convention for naming the private method that I have called " _Add " here? I am not a fan of the leading underscore but it is what one of my teammates suggests. public Vector Add(Vector vector) { // check vector for null, and compare Length to vector.Length return _Add(vector); } public static Vector Add(Vector vector1, Vector vector2) { // check parameters for null, and compare Lengths Vector returnVector = vector1.Clone() return returnVector._Add(vector2); } private Vector _Add(Vector vector) { for (int index = 0; index < Length; index++) { this[index] += vector[index]; } return

When/why to make function private in class?

穿精又带淫゛_ 提交于 2019-11-28 08:18:25
When should i make a function private and why is it good idea? You should make a function private when you don't need other objects or classes to access the function, when you'll be invoking it from within the class. Stick to the principle of least privilege , only allow access to variables/functions that are absolutely necessary. Anything that doesn't fit this criteria should be private . I usually make the helper functions private . But what is helper seems to be vague. So let me give you an example. Suppose you've the following class Sample ; it exposes few public functions, one of them,

Private interface methods are supported

北慕城南 提交于 2019-11-28 04:49:10
问题 Private interface methods are supported by Java 9. This support allows non-abstract methods of an interface to share code between them. Private methods can be static or instance. Can private methods of an interface be abstract or default ? May I ask for an example where " private static interface methods" are useful in terms of code? 回答1: No , the private methods in the interfaces are supposedly designed for clubbing in a piece of code that is internal to the interface implementation. Since