class-design

How do I break my procedural coding habits? [closed]

我是研究僧i 提交于 2019-12-20 09:55:10
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I recently read an interesting comment on an OOP related question in which one user objected to creating a "Manager" class: Please remove the word manager from your vocabulary when talking about class names. The name of the class should be descriptive of its' purpose. Manager

Which class design is better? [closed]

青春壹個敷衍的年華 提交于 2019-12-20 08:05:08
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Which class design is better and why? public class User { public String UserName; public String Password; public String FirstName; public String LastName; } public class Employee : User { public String EmployeeId; public String EmployeeCode; public String DepartmentId; } public

Which class design is better? [closed]

梦想的初衷 提交于 2019-12-20 08:03:05
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Which class design is better and why? public class User { public String UserName; public String Password; public String FirstName; public String LastName; } public class Employee : User { public String EmployeeId; public String EmployeeCode; public String DepartmentId; } public

C++ classes with members referencing each other

十年热恋 提交于 2019-12-20 03:31:46
问题 I'm trying to write 2 classes with members that reference each other. I'm not sure if I'm doing something wrong or it's just not possible. Can anyone help me out here... Source.cpp #include "Headers.h" using namespace std; void main() { Network* network = new Network(); system("pause"); return; } Headers.h #ifndef Headers_h #define Headers_h #include <iostream> #include <vector> #include "Network.h" #include "Router.h" #endif Network.h #include "Headers.h" class Network { protected: vector

Should a class have the same name as the namespace?

时光毁灭记忆、已成空白 提交于 2019-12-19 20:00:29
问题 I'm designing a namespace to hold a set of classes that will handle user related tasks for a several different applications. (Log-in, authenticate etc) The problem is the namespace will be called Fusion.User but then it requires a class in that namespace that makes sense to call User . Should you have a class with the same name as the namespace? Or am I taking the wrong approach here? 回答1: Having class named in the same way as the name space (package) may lead to a thought that class is

C++, preventing class instance from being created on the stack (during compiltaion)

坚强是说给别人听的谎言 提交于 2019-12-18 11:33:27
问题 I know there are methods to prevent a class from being created on the heap, by preventing the user from using the new and delete operator. I am trying to do just the opposite. I have a class that I want to prevent the user from creating an instance of it on the stack, and that only instances instigated using the new operator will compile. More specifically, I want the following code to receive an error during compilation: MyClass c1; //compilation error MyClass* c1 = new MyClass(); //compiles

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

五迷三道 提交于 2019-12-18 11:09:10
问题 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

List<BusinessObject> or BusinessObjectCollection?

做~自己de王妃 提交于 2019-12-18 10:13:32
问题 Prior to C# generics, everyone would code collections for their business objects by creating a collection base that implemented IEnumerable IE: public class CollectionBase : IEnumerable and then would derive their Business Object collections from that. public class BusinessObjectCollection : CollectionBase Now with the generic list class, does anyone just use that instead? I've found that I use a compromise of the two techniques: public class BusinessObjectCollection : List<BusinessObject> I

The point of an Interface [duplicate]

二次信任 提交于 2019-12-18 05:59:16
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How will I know when to create an interface? I'm wondering about the point of using an Interface. Do you use Interfaces? If so, when do you decide to use them and when do you decide NOT to use them? I've currently got interfaces defined for my service layers and my repository layers, but I'm wondering if I'm missing out on other places where they'd be useful. I guess I just don't fully understand their purpose.

The best way to share database connection between classes

孤人 提交于 2019-12-18 05:10:30
问题 I would like to be able to hide my database connection from print_r so I am using a static variable. I have a base class and a few object classes. Ideally they would all share the same database connection. What is the best way of sharing this? The way I have it set up now "works" but it just doesnt feel right. Must be a better way of doing this. (logically the classes shouldnt inherit one another) class base { private static $db; function __construct() { self::$db = new DB(); // our database