class-design

UML Class Diagram for User Login

妖精的绣舞 提交于 2019-11-28 14:12:29
问题 The diagram below is my very first attempt at creating a UML class diagram describing a user login into a website. I'm sure its a poor design and full of flaws, but I'm hoping to learn from you guys how you would design a simple login like this. I'm particularly interested in your use of design patterns and which patterns you would use, how you would implement it in the design, and why. Any advise, criticisms, comments and suggestions will be really appreciated. Thanks in advance. 回答1: Here

Design of std::ifstream class

放肆的年华 提交于 2019-11-28 13:46:21
Those of us who have seen the beauty of STL try to use it as much as possible, and also encourage others to use it wherever we see them using raw pointers and arrays . Scott Meyers have written a whole book on STL, with title Effective STL . Yet what happened to the developers of ifstream that they preferred char* over std::string . I wonder why the first parameter of ifstream::open() is of type const char* , instead of const std::string & . Please have a look at it's signature: void open(const char * filename, ios_base::openmode mode = ios_base::in ); Why this? Why not this: void open(const

Varieties of @interface declarations, some with parentheses

僤鯓⒐⒋嵵緔 提交于 2019-11-28 13:41:41
I've noticed a variety of @interface declarations for Objective-c classes. I'd like to understand why developers declare @interface in the following ways: // in the .h file @interface MyClass : NSObject // ... @end // in the .m file (what's the purpose of the parens?) @interface MyClass () // more property declarations which seem like they can go in the .h file @end // again in the .m file (what's the purpose of private?) @interface MyClass (Private) // some method declarations @end This is just a normal class interface , inheriting from NSObject, where you declare ivars, properties and

In C#, use of value types vs. reference types

主宰稳场 提交于 2019-11-28 12:07:14
My questions are: When should we use value types and when reference types? What are the advantages and disadvantages of one over other? What if one uses reference types everywhere? Is there any harm in it? Please also discuss advantages and disadvantages of each one. I want to understand that as well. Repo Man There seems to be a lot of confusion over this, and Jon Skeet does a good job of clearing it up in his book "C# In Depth, 2nd Ed." (section 2.3). My personal approach, which may or may not be right, is to ONLY use structs/enumerations (value types) to represent lightweight, atomic data

Class design vs. IDE: Are nonmember nonfriend functions really worth it?

对着背影说爱祢 提交于 2019-11-28 08:39:58
问题 In the (otherwise) excellent book C++ Coding Standards, Item 44, titled "Prefer writing nonmember nonfriend functions" , Sutter and Alexandrescu recommend that only functions that really need access to the members of a class be themselves members of that class. All other operations which can be written by using only member functions should not be part of the class. They should be nonmembers and nonfriends. The arguments are that: It promotes encapsulation, because there is less code that

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,

Is it possible to assign an array to a class property by reference rather than a copy?

对着背影说爱祢 提交于 2019-11-28 08:16:21
问题 Background: I designed a TableViewDataSource class that provides an implementation for UITableViewDataSource and UITableViewDelegate . You instantiate TableViewSection objects, which are passed to the TableViewDataSource which are used to configure cells, section headers, handle selection, row insertion, etc. The TableViewSection object has a property called dataSource: [AnyObject]? , which, when set, is used to calculate the number of rows in the section, and provide an object for the cell

Howto design for extension

霸气de小男生 提交于 2019-11-28 07:31:02
There is a Checkstyle rule DesignForExtension . It says: if you have a public/protected method which is not abstract nor final nor empty it is not "designed for extension". Read the description for this rule on the Checkstyle page for the rationale. Imagine this case. I have an abstract class which defines some fields and a validate method for those fields: public abstract class Plant { private String roots; private String trunk; // setters go here protected void validate() { if (roots == null) throw new IllegalArgumentException("No roots!"); if (trunk == null) throw new

Using a class' __new__ method as a Factory: __init__ gets called twice

旧城冷巷雨未停 提交于 2019-11-28 04:53:56
I encountered a strange bug in python where using the __new__ method of a class as a factory would lead to the __init__ method of the instantiated class to be called twice. The idea was originally to use the __new__ method of the mother class to return a specific instance of one of her children depending on the parameters that are passed, without having to declare a factory function outside of the class. I know that using a factory function would be the best design-pattern to use here, but changing the design pattern at this point of the project would be costly. My question hence is: is there

this pointer to base class constructor?

天大地大妈咪最大 提交于 2019-11-28 04:35:33
问题 I want to implement a derived class that should also implement an interface, that have a function that the base class can call. The following gives a warning as it is not safe to pass a this pointer to the base class constructor: struct IInterface { void FuncToCall() = 0; }; struct Base { Base(IInterface* inter) { m_inter = inter; } void SomeFunc() { inter->FuncToCall(); } IInterface* m_inter; }; struct Derived : Base, IInterface { Derived() : Base(this) {} FuncToCall() {} }; What is the best