class-design

Is UML practical? [closed]

。_饼干妹妹 提交于 2019-11-26 23:37:26
In college I've had numerous design and UML oriented courses, and I recognize that UML can be used to benefit a software project, especially use-case mapping, but is it really practical? I've done a few co-op work terms, and it appears that UML is not used heavily in the industry. Is it worth the time during a project to create UML diagrams? Also, I find that class diagrams are generally not useful, because it's just faster to look at the header file for a class. Specifically which diagrams are the most useful? Edit: My experience is limited to small, under 10 developer projects. Edit: Many

Calling method that exists in child classes but not in parent class

爷,独闯天下 提交于 2019-11-26 23:35:58
问题 public class Parent { .... } public class Child1 extends Parent { .... public void foo() { .... } } public class Child2 extends Parent { .... public void foo() { .... } } Here method foo() only exists in the Child classes and CAN NOT be added to the Parent class (not even abstract method). In this situation when I want to call the foo() method on obj which is Parent class's reference then I need to use intanceof with multiple if..else which I want to avoid. Parent obj = ...// Object of one of

Ruby - share logger instance among module/classes

痴心易碎 提交于 2019-11-26 22:29:50
问题 Working on a little Ruby script that goes out to the web and crawls various services. I've got a module with several classes inside: module Crawler class Runner class Options class Engine end I want to share one logger among all those of those classes. Normally I'd just put this in a constant in the module and reference it like so: Crawler::LOGGER.info("Hello, world") The problem is that I can't create my logger instance until I know where the output is going. You start the crawler via

What's the most reliable way to prohibit a copy constructor in C++?

ε祈祈猫儿з 提交于 2019-11-26 22:23:36
Sometimes it's necessary to prohibit a copy constructor in a C++ class so that class becomes "non-copyable". Of course, operator= should be prohibited at the same time. So far I've seen two ways to do that. Way 1 is to declare the method private and give it no implementation: class Class { //useful stuff, then private: Class( const Class& ); //not implemented anywhere void operator=( const Class& ); //not implemented anywhere }; Way 2 is to declare the method private and give it "empty" implementation: class Class { //useful stuff, then private: Class( const Class& ) {} void operator=( const

How do I alias a class name in C#, without having to add a line of code to every file that uses the class?

允我心安 提交于 2019-11-26 17:26:12
问题 i want to create an alias for a class name. The following syntax would be perfect: public class LongClassNameOrOneThatContainsVersionsOrDomainSpecificName { ... } public class MyName = LongClassNameOrOneThatContainsVersionOrDomainSpecificName; but it won't compile. Example Note This example is provided for convience only. Don't try to solve this particular problem by suggesting changing the design of the entire system. The presence, or lack, of this example doesn't change the original

How do I alias a class name in C#, without having to add a line of code to every file that uses the class?

独自空忆成欢 提交于 2019-11-26 14:36:17
i want to create an alias for a class name. The following syntax would be perfect: public class LongClassNameOrOneThatContainsVersionsOrDomainSpecificName { ... } public class MyName = LongClassNameOrOneThatContainsVersionOrDomainSpecificName; but it won't compile. Example Note This example is provided for convience only. Don't try to solve this particular problem by suggesting changing the design of the entire system. The presence, or lack, of this example doesn't change the original question. Some existing code depends on the presence of a static class: public static class ColorScheme { ...

PHP 5: const vs static

爱⌒轻易说出口 提交于 2019-11-26 11:50:59
问题 In PHP 5, what is the difference between using const and static ? When is each appropriate? And what role does public , protected and private play - if any? 回答1: In the context of a class, static variables are on the class scope (not the object) scope, but unlike a const, their values can be changed. class ClassName { static $my_var = 10; /* defaults to public unless otherwise specified */ const MY_CONST = 5; } echo ClassName::$my_var; // returns 10 echo ClassName::MY_CONST; // returns 5

OO Javascript constructor pattern: neo-classical vs prototypal

て烟熏妆下的殇ゞ 提交于 2019-11-26 11:48:41
问题 I watched a talk by Douglas Crockford on the good parts in Javascript and my eyes were opened. At one point he said, something like, \"Javascript is the only language where good programmers believe they can use it effectively, without learning it.\" Then I realized, I am that guy. In that talk, he made some statements that for me, were pretty surprising and insightful. For example, JavaScript is the most important programming language on the planet. Or it is the most popular language on the

How would you code an efficient Circular Buffer in Java or C#?

寵の児 提交于 2019-11-26 11:14:24
I want a simple class that implements a fixed-size circular buffer . It should be efficient, easy on the eyes, generically typed. For now it need not be MT-capable . I can always add a lock later, it won't be high-concurrency in any case. Methods should be: .Add() and I guess .List() , where I retrieve all the entries. On second thought, Retrieval I think should be done via an indexer. At any moment I will want to be able to retrieve any element in the buffer by index . But keep in mind that from one moment to the next Element[n] may be different, as the circular buffer fills up and rolls over

Why is 16 byte the recommended size for struct in C#?

天涯浪子 提交于 2019-11-26 09:44:09
问题 I read the Cwalina book (recommendations on development and design of .NET applications). He says that a good designed struct has to be less than 16 bytes in size (for performance purposes). Why exactly is this? And (more important) can I have larger struct with same efficiency if I run my .NET 3.5 (soon to be .NET 4.0) 64-bit application on Core i7 under Windows 7 x64 (is this limitation CPU / OS based)? Just to stress again - I need as efficient struct as it is possible. I try to keep it on