class-design

Class design with vector as a private/public member?

折月煮酒 提交于 2019-12-11 03:33:30
问题 what is the best way to put a container class or a some other class inside a class as private or a public member? Requirements: 1.Vector< someclass> inside my class 2.Add and count of vector is needed interface 回答1: If the container's state is part of the class's invariant, then it should, if possible, be private. For example, if the container represents a three dimensional vector then part of the invariant might be that it always contains exactly 3 numbers. Exposing it as a public member

Refactoring class design to convey the design intention

久未见 提交于 2019-12-11 03:22:54
问题 I have following class design. The complete code is available in " How to achieve this functionality using Generics? ". The code works fine and resolves the casting issue mentioned in " Refactoring Code to avoid Type Casting " In the RetailInvestmentReturnCalculator class, the GetInvestmentProfit() method utilizes CalculateBaseProfit() method present in InvestmentReturnCalculator abstract base class. This fact is not evident from the class design. QUESTION How to refactor this class design to

Adding function to string class

巧了我就是萌 提交于 2019-12-10 17:56:33
问题 I understand that inheriting from std::string class is a poor idea, but was just trying to add a custom function to string class for a dummy assignment, using inheritance. I want to call my function as 'add' and when I do str.add(str1,str2); it should append str1 at the beginning of the string and str2 at the end of the string. This class(inherited string class) is a private member class of another class(say Parent). when I try to access my string class object with this, it points to the

What constitutes a rich domain model in a POJO/POCO?

牧云@^-^@ 提交于 2019-12-10 16:48:04
问题 What is the difference between A simple fields-accesors-mutators class A rich-modeled class What constitutes rich modeling in business-domain classes? 回答1: "Rich" as used here implies "rich behavior" (as opposed to state). There is technical behavior and domain behavior. Accessors and mutators are technical; they lack the "why" which defines business interest. Domain objects represent the "why" and encapsulate the "how". Actually, all objects do that; domain objects do it specifically for

Can I tell .net's Intellisense how to sort fields?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 16:13:36
问题 In Visual Studio, Intellisense sorts the fields of an object by alphabetical order. I am used to Delphi, where Intellisense sorts by (method, property, event) and then alphabetically. Is there a decoration once can add to a class/struct definition to tell Intellisense how to sort fields? 回答1: Unfortunately you cannot. It's a feature that's been requested but just hasn't made it in yet. 来源: https://stackoverflow.com/questions/4116688/can-i-tell-nets-intellisense-how-to-sort-fields

How to map objects with UI

喜夏-厌秋 提交于 2019-12-10 12:18:55
问题 I have following class implementation (not complete, just to give an idea) public class MySwitch{ Command command = Command.Red; public Command GetNext() { command = GetNext(command); // circular enum values return command; } } public enum Command { Red =0, Blue=1, Green=2} public class LED { public void Glow(Command command){ this.setColor(ColorForm(command)); this.Glow(); } } public class Commander { public Commander(LED target, MySwitch source){ this.LED = LED; this.MySwitch = MySwitch; }

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

纵饮孤独 提交于 2019-12-10 09:32:05
问题 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() { //

Why put private fields and methods at the top of class?

天涯浪子 提交于 2019-12-10 00:38:05
问题 I've seen this de facto standard in many places in many languages, but I've never understood it - why put your private fields and methods at the top of a class declaration? Metaphorically it seems like private things should be located at the bottom (hidden) and everything public should be at the top, so that when you read through the class top to bottom you first see the public interface then the inner workings. What is the reasoning behind this? EDIT: Just to clarify, I don't mean the

How to add callback function to a javascript class?

江枫思渺然 提交于 2019-12-09 13:48:27
问题 The following code in javascript gives me the error "this.callback is not a function function ajaxRequest() { var httpObject; this.open = open; this.callback = function(){}; function getHTTPObject() { if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else { alert("Your browser does not support AJAX."); return null; } } function onstatechange() { if(httpObject.readyState == 4) { this.callback(httpObject

C++ Cache Design Advice

时间秒杀一切 提交于 2019-12-09 13:15:46
问题 I have a c++ application with several image types(RGB, Gray...) and every type has properties like Rotation or Scale. Every image type is generated via some computation from the other types. For example, A rotated GrayImage is generated by rotating a GrayImage which in turn is generated by "graying" an RGBImage . I would like to design a cache class with methods GetX(...) that caches the various images (and possibly all images in the computation path). This class would also know how to