public-method

Public static methods - a bad sign?

不羁的心 提交于 2020-01-02 07:20:14
问题 I've just read this article here: http://hamletdarcy.blogspot.com/2008/04/10-best-idea-inspections-youre-not.html, and the last bit in particular got me thinking about my code, specifically the advice: What in the world is a public method doing on your object that has no dependency on any fields within the object? This is certainly a code smell. The problem is that the "auto-fix" for the inspection is to apply the static keyword. Nooooo. That's not what you want to do. A public method without

public static factory method

孤街浪徒 提交于 2019-12-30 00:53:05
问题 First of all please forgive me if its a really dumb question, I am just trying to learn this language to its core. I am reading Effective Java and the very first chapter talks about Static factory methods vs. Constructors. Their pros and cons. Few things that are confusing to me are: class of an object returned by static factory method is nonpublic - what exactly does it mean? unlike constructors static factory methods are not required to create a new object each time they are invoked - How

Methods in java (grade calculator)

心不动则不痛 提交于 2019-12-20 07:47:52
问题 We've been learning about methods in java (using netbeans) in class and I'm still a bit confused about using methods. One homework question basically asks to design a grade calculator using methods by prompting the user for a mark , the max mark possible, the weighting of that test and then producing a final score for that test. eg. (35/50)*75% = overall mark However, I am struggling to use methods and I was wondering if someone could point me in the right direction as to why my code below

Private Methods Over Public Methods

心不动则不痛 提交于 2019-12-17 23:44:32
问题 I was examining the StringTokenizer.java class and there were a few questions that came to mind. I noticed that the public methods which are to be used by other classes invoked some private method which did all of the work. Now, I know that one of the principles of OOD is to make as much as you can private and hide all of the implementation details. I'm not sure I completely understand the logic behind this though. I understand that it's important to make fields private to prevent invalid

Is there a custom FxCop rule that will detect unused PUBLIC methods?

落花浮王杯 提交于 2019-12-17 19:29:01
问题 I just tried FxCop. It does detect unused private methods, but not unused public. Is there a custom rule that I can download, plug-in that will detect public methods that aren't called from within the same assembly? 回答1: Corey, my answer of using FxCop had assumed you were interested in removing unused private members, however to solve the problem with other cases you can try using NDepend. Here is some CQL to detect unused public members (adapted from an article listed below): // <Name

What are the differences between “private”, “public”, and “protected methods”?

旧巷老猫 提交于 2019-12-17 17:49:07
问题 I'm learning Ruby, and have come up to a point where I am confused. The book I am using is talking about private , public , and protected methods , but I am still a bit confused. What are the differences between each? 回答1: Public - can be called from anywhere Private - The method cannot be called outside class scope. The object can only send the message to itself ex: the baker has bake method as public but break_eggs is private Protected - You can call an object's protected methods as long as

javadoc exclude some public methods from class

落花浮王杯 提交于 2019-12-12 16:25:10
问题 I have to exclude a few of the public methods of a class from being included in javadocs. I tried Chris Nokleberg's ExcludeDoclet (sixlegs). But the doclet is giving a slight problem : If the other methods in the class return List (or any other generics), instead of being displayed in the javadoc as List, return type is just being displayed as List (without the generic info) Can anyone give a hint or provide a work around on how to solve this issue? 回答1: I assume the methods you want to

How to modify a Form and refresh it from another Form

邮差的信 提交于 2019-12-11 16:23:35
问题 I use two Forms: Form1 contains button1 Form2 contains button2 and Panel1 My project starts using Form2. Then I click on button2 to show Form1 private void button2_Click(object sender, EventArgs e) { Form1 Frm = new Form1(); Frm.Show(); } Then on Form1, I click on button1 to hide Panel1 on Form2 private void button1_Click(object sender, EventArgs e) { Form2 FormInstance = new Form2(); FormInstance.displayInit(); FormInstance.Refresh(); } displayInit() is a method inside Form2: public void

Is there a way in Ruby to print out the public methods of an Object

时光毁灭记忆、已成空白 提交于 2019-12-11 00:09:46
问题 ... without including all of the public methods of the generic Object? I mean, other than doing array subtraction. I just want to quickly review what's available to me from an object sometimes without going to the docs. 回答1: methods , instance_methods , public_methods , private_methods and protected_methods all accept a boolean parameter to determine if the methods of your object's parents are included. For example: ruby-1.9.2-p0 > class MyClass < Object; def my_method; return true; end; end;

How to easyily find unused public methods/properties

北慕城南 提交于 2019-12-10 03:50:00
问题 I have a .Net(C#) solution. The solution contains bunch of projects. The projects were implemented not by me. It is not a framework, it means that I need to have amount of public methods/properties as less as possible. My task is to identify methods and properties which are not used, but exist in the projects. Well, I can find private methods which are not used using R#. But it is completely unclear how to find public methods/properties which are not used. I heard that they have NDepend tool,