encapsulation

How to hide public methods from intellisense

放肆的年华 提交于 2019-11-26 10:57:34
问题 I want to hide public methods from the intellisense member list. I have created an attribute that when applied to a method will cause the method to be called when its object is constructed. I\'ve done this to better support partial classes. The problem is that in some environments (such as Silverlight), reflection cannot access private members even those of child classes. This is a problem since all of the work is done in a base class. I have to make these methods public, but I want them to

IEnumerable vs IReadonlyCollection vs ReadonlyCollection for exposing a list member

送分小仙女□ 提交于 2019-11-26 10:24:57
问题 I have spent quite a few hours pondering the subject of exposing list members. In a similar question to mine, John Skeet gave an excellent answer. Please feel free to have a look. ReadOnlyCollection or IEnumerable for exposing member collections? I am usually quite paranoid to exposing lists, especially if you are developing an API. I have always used IEnumerable for exposing lists, as it is quite safe, and it gives that much flexibility. Let me use an example here public class Activity {

Private vs. Public members in practice (how important is encapsulation?) [closed]

眉间皱痕 提交于 2019-11-26 09:37:18
问题 One of the biggest advantages of object-oriented programming is encapsulation, and one of the \"truths\" we\'ve (or, at least, I\'ve) been taught is that members should always be made private and made available via accessor and mutator methods, thus ensuring the ability to verify and validate the changes. I\'m curious, though, how important this really is in practice. In particular, if you\'ve got a more complicated member (such as a collection), it can be very tempting to just make it public

Why is it considered bad practice to use “global” reference inside functions? [duplicate]

Deadly 提交于 2019-11-26 09:14:18
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Are global variables in PHP considered bad practice? If so, why? global in functions Edit: question answered in link above. No, \"global\" in php is not the same thing as global in other languages, and while it does not introduce any security problems it can make the code less comprehensible to others. OP: Project summary - I am writing a web CMS to get my feet wet with PHP / MySQL. In order to break up the code

Simple way to understand Encapsulation and Abstraction

假如想象 提交于 2019-11-26 06:58:16
问题 Learning OOP concepts especially interested to understand Abstraction and Encapsulation in depth. Checked out the below already Abstraction VS Information Hiding VS Encapsulation difference between abstraction and encapsulation? I found very hard to understand those concepts with out a real and simple example class/code snippet. One of my colleagues said abstraction is nothing but creating abstract class and normal class that protects its member variable with scope is called Encapsulation. Is

Any reason to use auto-implemented properties over manual implemented properties?

六月ゝ 毕业季﹏ 提交于 2019-11-26 06:45:33
问题 I understand the advantages of PROPERTIES over FIELDS, but I feel as though using AUTO-implemented properties over MANUAL implemented properties doesn\'t really provide any advantage other than making the code a little more concise to look at it. I feel much more comfortable using: private string _postalCode; public string PostalCode { get { return _postalCode; } set { _postalCode = value; } } Instead of: public string PostalCode { get; set; } primarily because if I ever want to do any kind

Effective C++ Item 23 Prefer non-member non-friend functions to member functions

a 夏天 提交于 2019-11-26 06:32:12
问题 While puzzling with some facts on class design, specifically whether the functions should be members or not, I looked into Effective c++ and found Item 23, namely, Prefer non-member non-friend functions to member functions. Reading that at first hand with the web browser example made some sense, however convenience functions( named the nonmember functions like this in the book) in that example change the state of the class, don\'t they? So, first question, should not they be members then?

Set and Get Methods in java?

柔情痞子 提交于 2019-11-26 05:25:34
问题 How can I use the set and get methods, and why should I use them? Are they really helpful? And also can you give me examples of set and get methods? 回答1: Set and Get methods are a pattern of data encapsulation. Instead of accessing class member variables directly, you define get methods to access these variables, and set methods to modify them. By encapsulating them in this manner, you have control over the public interface, should you need to change the inner workings of the class in the

Good way to encapsulate Integer.parseInt()

家住魔仙堡 提交于 2019-11-26 04:34:04
I have a project in which we often use Integer.parseInt() to convert a String to an int. When something goes wrong (for example, the String is not a number but the letter a , or whatever) this method will throw an exception. However, if I have to handle exceptions in my code everywhere, this starts to look very ugly very quickly. I would like to put this in a method, however, I have no clue how to return a clean value in order to show that the conversion went wrong. In C++ I could have created a method that accepted a pointer to an int and let the method itself return true or false. However,

Properties vs. Fields: Need help grasping the uses of Properties over Fields

非 Y 不嫁゛ 提交于 2019-11-26 03:58:48
问题 First off, I have read through a list of postings on this topic and I don\'t feel I have grasped properties because of what I had come to understand about encapsulation and field modifiers (private, public..ect). One of the main aspects of C# that I have come to learn is the importance of data protection within your code by the use of encapsulation. I \'thought\' I understood that to be because of the ability of the use of the modifiers (private, public, internal, protected). However, after