class-design

In .NET, Why Can I Access Private Members of a Class Instance within the Class?

北战南征 提交于 2019-12-07 01:16:47
问题 While cleaning some code today written by someone else, I changed the access modifier from Public to Private on a class variable/member/field. I expected a long list of compiler errors that I use to "refactor/rework/review" the code that used this variable. Imagine my surprise when I didn't get any errors. After reviewing, it turns out that another instance of the Class can access the private members of another instance declared within the Class. Totally unexcepted. Is this normal? I been

How to convert C++ class/struct to a primitive/different type/class/struct?

心不动则不痛 提交于 2019-12-06 14:53:21
I have the following class CppProperty class that holds value: template<typename TT> class CppProperty { TT val; public: CppProperty(void) { } CppProperty(TT aval) : val(aval) { } CppProperty(const CppProperty & rhs) { this->val = rhs.val; } virtual ~CppProperty(void) { } TT operator=(TT aval) { this->val = aval; return this->val; } friend TT operator++(CppProperty & rhs); friend TT operator--(CppProperty & rhs); friend TT operator++(CppProperty & rhs, int); friend TT operator--(CppProperty & rhs, int); //template<typename RR> //friend RR operator=(RR & lhs, const CppProperty & rhs); //friend

MVC3 - Where is UserId and Roles information

走远了吗. 提交于 2019-12-06 11:08:16
This is the Model code generated in MVC3 for Account/Membership class for a sample project I created. I do not see UserId field/attribute or Roles information.. Where is the UserId and Roles information ? public class ChangePasswordModel { [Required] [DataType(DataType.Password)] [Display(Name = "Current password")] public string OldPassword { get; set; } [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "New password")] public string NewPassword { get; set; } [DataType(DataType

Cleaning up in Shutdown() method instead of destructor

这一生的挚爱 提交于 2019-12-06 05:50:13
问题 In Rastertek DirectX tutorials they have empty constructors and destructors and instead use initialize() and shutdown() functions for objects initialization and cleaning up. After using this design for a while I can somewhat understand the benefits of having an initialize() method, but I can't see how using a shutdown() method is any better than putting all the clean-up code in the destructor. The reason they provide is the following: You will also notice I don't do any object clean up in the

Design(How-to) of classes containing collections of other classes

删除回忆录丶 提交于 2019-12-06 03:33:33
问题 How to design classes involving collections of other classes? General Example: A Workspace contains number of Projects . A Project contains large number of Resources . Each Resource may contain large number of Files . So here the classes identified can be Workspace,Project,Resource and File. Workspace will have list of Project.Project will have list of Resources and Resource will have list of Files. Of course each class has its related settings. Now the basic questions are : a) Who creates

What is the limit N of maximum methods you allow in your classes?

谁说胖子不能爱 提交于 2019-12-05 22:59:12
While filling in The Object Oriented Concepts Survey (To provide some academic researchers with real-life data on software design), I came upon this question: What is the limit N of maximum methods you allow in your classes? The survey then goes on asking if you refactor your classes once you reach this limit N. I've honestly never thought about such a limit while designing my applications and wonder what the reasoning behind this is. Why would I want to self-impose myself an arbitrary number which probably is very dependent on the classes functionality? You don't have to limit N of maximum.

Python: How should I make instance variables available?

霸气de小男生 提交于 2019-12-05 17:35:24
Suppose I have: class myclass: def __init__(self): self.foo = "bar" where the value of foo needs to be available to users of myclass. Is it OK to just read the value of foo directly from an instance of myclass? Should I add a get_foo method to myclass or perhaps add a foo property? What's the best practice here? The applicable Python maxim would be "we're all adults here" - if users need direct access to the value of foo , let them access it directly. A getter or property would make sense if you need to run some code when it's accessed, otherwise the direct way is best. Also, you can always

Javascript: How to access a class attribute from a function within one of the class's functions

北城以北 提交于 2019-12-05 16:23:54
Within my a certain function of a class, I need to use setInterval to break up the execution of the code. However, within the setInterval function, "this" no longer refers to the class "myObject." How can I access the variable "name" from within the setInterval function? function myObject() { this.name = "the name"; } myObject.prototype.getName = function() { return this.name; } myObject.prototype.test = function() { // this works alert(this.name); var intervalId = setInterval(function() { // this does not work alert(this.name); clearInterval(intervalId); },0); } myObject.prototype.test =

Objective-C partial implementation of classes in separate files

流过昼夜 提交于 2019-12-05 07:00:22
I am using core data and am generating classes from my data model. I implement custom methods in these classes, however when i regenerate i generate over the top so i end up copying and pasting a bit. What i would like to do is split my implementation files ('.m') so i can have one header file with multiple '.m' files. then i can keep my custom methods in one and not have to worry about erasing them when i regenerate. I use this technique in .NET a lot with its partial keyword. Is there anything similar in objective-C You may also want to look at mogenerator , which takes a different approach

Class design suggestions: extending a class and code reuse

让人想犯罪 __ 提交于 2019-12-05 06:58:10
The gist of this question is about extending a class, minimizing jam-packing everything into a single class, and maximizing code re-use. After reading this question, please feel free to edit the title or description to make it more succinct. Though the post looks long, I am just trying to be thorough by using a lot of examples. Suppose I have a class: class UsedByManyPeople { // ...has many fields }; As the name implies, this class is used by a lot of developers. I have to add 2 features to this class: a convert() that converts UsedByManyPeople to SomeOtherType a getFileName() that returns a