0
votes
1answer
105 views

When should I refactor a private class into a package-private class?

When I began implementing a class in my system (let's call it A), I realized I needed some kind of object that does something. So I needed a new class (let's call it B), but I made it a private static ...
0
votes
0answers
56 views

Is it good to make singleton Log classes for Entity classes [duplicate]

I am little confused about the technique i use in almost all applications i wrote ,i think i am going wrong I make Entity class Forexample Person, Adress ,Class and then to save it i make AdressLog ...
2
votes
1answer
73 views

class hierarchy with structurally different subclasses

I want to implement a protocol layer which sits on top of the TCP/IP stack. There is a limited set of PDUs that can be sent and for each PDU there is a class which represents it in a structured form. ...
1
vote
2answers
85 views

How specific should be an interface about its implementation details?

Perhaps I should have picked a better title, but anyway... Basically what to do with two or more implementations that have the same public interface, but they are meant for slightly different ...
1
vote
7answers
666 views

Significant amount of the time, I can't think of a reason to have an object instead of a static class. Do objects have more benefits than I think? [closed]

I understand the concept of an object, and as a Java programmer I feel the OO paradigm comes rather naturally to me in practice. However recently I found myself thinking: Wait a second, what are ...
2
votes
1answer
183 views

UML class diagrams: How to show dependency

Please consider a program with four classes: Class A, B, C and D. Classes A and B are subclasses of abstract super-class C. Class D is dependent on C. Meaning: It holds a C objectOfTypeC field. As ...
25
votes
8answers
4k views

Why have private static methods?

I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility? I would have thought an advantage to having a ...
1
vote
5answers
171 views

Clarification about Polymorphism / Inheritance

I am trying to better my understanding of polymorphism. Say I have a base class called baseClass with one method called foo() and I have three derived classes called derived1 , derived2 and derived3 ...
1
vote
1answer
127 views

Dynamic method creation in python

I have a class that will have a number of external methods that will all call the same smaller set of internal methods. So something like: obj.method_one(a, c) and obj.method_two(a, c) where ...
1
vote
1answer
452 views

Is it good or bad practice to provide separate classes for an object: one to build it, and one to use it?

Suppose I'm writing some C++ code to visualize "Foo" objects. I have two ways of getting a "Foo": computing it from data, or from taking the pieces of a precomputed "Foo" and building a new "Foo". ...
0
votes
2answers
311 views

In PHP, should I delete objects immediately after use?

I've read in PHP Advanced and Object Oriented Programming by Larry Ullman that it is good programming practice to delete object immediately after use but reason is given nowhere. I am a student web ...
13
votes
6answers
2k views

Should a class know about its subclasses?

Should a class know about its subclasses? Should a class do something that is specific for a given subclass for instance? My instincts tells me that is a bad design, it seems like an anti-pattern of ...
2
votes
3answers
1k views

Specific reasons to create own array class over using std::array?

What specific conditions or requirements should you create your own array over using std::array? Here is my background: I'm developing a small simple library that a small group of people will use ...
0
votes
2answers
155 views

Is it valid to initialize an instance of a class within the same class?

I was wondering if it's valid to initialize an instance of a class within the same class? For example: public class Person() { string name; string age; public Person getPerson() { ...
2
votes
2answers
220 views

Start by Teaching Classes [closed]

In every class, and every book I have seen regarding programming, classes are held off. They are thought to be confusing and strange. I certainly had issues with them. But in object orient ...
1
vote
4answers
3k views

Keeping track of all objects of a class

I'm new to object-oriented programming, and I keep running into this issue. (I'm programming in Java) I've been a bit reluctant to ask about this, since it seems like such a basic issue, but I can't ...
20
votes
4answers
1k views

How do purely functional languages handle modularity?

I come from an object oriented background where I've learned that classes are or at least can be used to make a layer of abstraction that allows for easy recycling of code which can then either be ...
4
votes
4answers
2k views

Was C designed to facilitate Object-Oriented programming?

I am trying to broaden my understanding of the history and development of object-oriented programming, and I am curious to find out if C was designed to facilitate Object-Oriented programming? (like ...
0
votes
1answer
269 views

Teaching `class`es and objects in C++ to university students

To learn classes and objects at my university, students are required to develop a simple game (nine-mens morris or something similar) using Java. Java is used because of its libraries and tool ...
1
vote
1answer
460 views

Analogy of a class being a cookie cutter and objects being cookies

I came across the analogy of the class being a cookie cutter and the cookies being objects while reading Code Complete. I fail to see why this analogy was drawn.How is it related to the concept of ...
1
vote
1answer
205 views

Is there a good design pattern for this messaging class?

Is there a good design pattern for this? I want to create a messaging class. The class will be passed: the type of message (eg. signup, signup confirmation, password reminder etc) the client's id ...
33
votes
6answers
3k views

How do I prove or disprove “god” objects are wrong?

Problem Summary: Long story short, I inherited a code base and a development team I am not allowed to replace and the use of God Objects is a big issue. Going forward, I want to have us re-factor ...
16
votes
5answers
1k views

Why am I seeing so many instantiable classes without state?

I'm seeing a lot of instantiable classes in the C++ and Java world that don't have any state. I really can't figure out why people do that, they could just use a namespace with free functions in C++, ...
-3
votes
8answers
2k views

Why do we need to separate classes which have different functionality? [closed]

Why do we need to separate classes which have different functionality? For example, why should we separate a car class from a paint class. What would be the OOD concept behind this? Is there anything ...
1
vote
1answer
106 views

How to represent association in programs [closed]

Could someone help me in implementing association in cpp. I am trying to implement a dice game where I have two classes a diegame and a dice.
43
votes
11answers
9k views

Why is it good to split a program into multiple classes? [closed]

I'm still a student in high school (entering 10th grade), and I have yet to take an actual computer course in school. Everything I've done so far is through books. Those books have taught me concepts ...
-1
votes
1answer
652 views

What is the difference between class level attributes, Class constants and singleton methods?

What the difference given they all exist 'once per class'. When should I use one over another, i.e. for what purpose? I use Ruby.
0
votes
2answers
2k views

Is it best practice to always capitalize class file names in PHP, and other languages?

I ask because I've seen a couple of OO PHP tutorials which do not adhere to this, but to me it just makes sense. It makes it easy to instantly see if a file is a class or not, if non-class files all ...
14
votes
7answers
6k views

What are the roles of singletons, abstract classes and interfaces?

I am studying OOP in C++ and, even though I am aware of the definitions of these 3 concepts, I cannot really realize when or how to use it. Let's use this class for the example: class Person{ ...
0
votes
3answers
282 views

Any language where every class instance is a class too?

Taking inspiration from Javascript prototypes, I had the idea of a language where every instance can be used as a class. Before I potentially reinvent the wheel, I would like to ask if there is a ...
2
votes
2answers
124 views

Would be semantically correct to make a “Login” constructor in an api class?

Since the methods of the class will only work if the user is logged in, is it right or is there some problem that might make my code slow/inneficient?
4
votes
3answers
1k views

Is this the correct approach to an OOP design structure in php?

I'm converting a procedural based site to an OOP design to allow more easily manageable code in the future and so far have created the following structure: /classes /templates index.php With these ...
2
votes
3answers
331 views

Want to know performance issues of Class types & access modifiers

Someone suggested me to mark classes as SEALED that are not being inherited anywhere. I was using default style and was not concerned with the type of class. At present I don't have a benchmark tool ...
11
votes
4answers
796 views

Nested Classes: A useful tool or an encapsulation violation?

So I'm still on the fence as to whether or not I should be using these or not. I feel its an extreme violation of encapsulation, however I find that I am able to achieve some degree of encapsulation ...