class-design

What does a compiler add to an empty class declaration?

半世苍凉 提交于 2019-11-30 17:33:57
问题 Suppose, I write class A { }; The compiler should provide (as and when needed) a constructor a destructor a copy constructor = operator Is this all the compiler provides? Are there any additions or deletions to this list? 回答1: It's complete. But there are two points you should note: It's the copy =operator. Just like there is a copy constructor, there is a copy assignment operator. They are only provided if actually used. Some explanation for 2: struct A { private: A(); }; struct B : A { };

Class prototyping

随声附和 提交于 2019-11-30 08:24:08
问题 I have put several instances of class b in class a but this causes an error as class a does not know what class b is. Now I know I can solve this problem by writing my file b a c but this messes up the reachability as well as annoys me. I know I can prototype my functions so I do not have this problem but have been able to find no material on how to prototype a class. does anyone have an example of class prototyping in c++. as there seems to be some confusion let me show you what i want class

Core Data entity inheritance --> limitations?

时光毁灭记忆、已成空白 提交于 2019-11-30 05:23:50
问题 I thought I'll post this to the community. I am using coredata, and have two entities. Both entities have a hierarchical relationship. I am noticing quite a lot of duplicated functionality now, and am wondering if I should re-structure to have a base Entity which is abstract (HierarchicalObject), and make my entities inherit from them. So the question is are there some limitations of this inheritance that I should take into account? Reading some of the posts out there, I see a few trade-offs,

How to share data between separate classes in Java

丶灬走出姿态 提交于 2019-11-30 05:13:43
What is the best way to share data between separate classes in Java? I have a bunch of variables that are used by different classes in separate files in different ways. Let me try to illustrate a simplified version of my problem: This was my code before: public class Top_Level_Class(){ int x, y; // gets user input which changes x, y; public void main(){ int p, q, r, s; // compute p, q, r, s doA(p,q,r); doB(q,r,s); } public void doA(int p, int q, int r){ // do something that requires x,y and p, q, r } public void doB(int q, int r, int s){ // does something else that requires x, y and q, r, s }

Python Class vs. Module Attributes

吃可爱长大的小学妹 提交于 2019-11-30 05:01:00
I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around? The problem I have with them, is that it is almost too easy to clobber a class attribute value by mistake, and then your "global" value has turned into a local instance attribute. Feel free to comment on how you would handle the following situations: Constant values used by a class and/or sub

“Public” nested classes or not

隐身守侯 提交于 2019-11-30 01:55:05
Suppose I have a class 'Application'. In order to be initialised it takes certain settings in the constructor. Let's also assume that the number of settings is so many that it's compelling to place them in a class of their own. Compare the following two implementations of this scenario. Implementation 1: class Application { Application(ApplicationSettings settings) { //Do initialisation here } } class ApplicationSettings { //Settings related methods and properties here } Implementation 2: class Application { Application(Application.Settings settings) { //Do initialisation here } class Settings

Android: can I use one SQLiteOpenHelper class for multiple database files?

丶灬走出姿态 提交于 2019-11-30 01:49:11
My app uses two databases (separate files). To handle these databases I have created two Helper classes which extend SQLiteOpenHelper, one for each database. I am now going to add a third database and wonder whether I need to create yet another Helper class (and if I used a 4th and a 5th database would I need even more Helper classes), or can I use the same Helper class for multiple databases? The problem that I see with trying to use just one Helper class is that I can't see how to pass the name of the individual database files to the Helper. At present the name of the database is hard-coded

In C#, what is the purpose of marking a class static?

a 夏天 提交于 2019-11-30 00:21:23
问题 In C#, what is the purpose of marking a class static? If I have a class that has only static methods, I can mark the class static or not. Why would I want to mark the class static? Would I ever NOT want to mark a class static, if all the methods are static, and if I plan to never add a non-static method? I looked around and saw some similar questions, but none that were just like this. 回答1: Marking a class as static is a declarative statement that you only intend for this type to have static

UML Class Diagram for User Login

邮差的信 提交于 2019-11-29 18:57:54
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. Arthur Ronald Here is how we implement this funcionallity As you can see, we have many Application (Here, it

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

跟風遠走 提交于 2019-11-29 14:42:23
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 needs access to the internals of a class. It makes writing function templates easier, because you don't