A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner
0
votes
2answers
141 views
When not to use an abstract super class?
Is there a use case/necessity (from design or implementation perspective) not to make a super class abstract?
Are there any differences in the programming language in use?
To make an example:
...
2
votes
3answers
90 views
How to compare objects with expanding amount of data?
Given a class like:
class State {
bool IsLessThan(State);
int data;
};
The State::IsLessThan(State) method can simply compare data in each class according to some logic. However let's say ...
0
votes
3answers
122 views
Variable name which sometimes refers to an object and sometimes to a string
Sorry for the confusing title - this is best illustrated by an example (hypothetical but hopefully illustrative).
For 99% of my application a Zip Code is considered as a string, so I consistently use ...
0
votes
0answers
44 views
How to update a model with dependencies
I'm having a bit of a hard time figuring this out. I have a model (which you can see in the image below) this model can be changed (it won't happen often, but it can). When it changes I do not get the ...
0
votes
0answers
23 views
Component needs to invoke class methods and instance methods (via ORM), how to structure
An interesting design choice/discussion has cropped up in code review, and I would like to understand more about proposed solutions. The original review includes re-factoring of a messy piece of code ...
-2
votes
1answer
109 views
Does this structure follow DDD/UoW pattern?
I am developing a Web API, with an n-tier approach, using Entity Framework and using code first approach.
My questions is does my DAL, and Business Logic layer are following DI/UoW/DDD pattern if not ...
0
votes
1answer
131 views
C# - How can I ensure a member is invoked without needing to call it and rely on the { get; }
I'm using reflection as a way of implementing a factory pattern:
Type type = GetProviderType(vendor);
ConstructorInfo constructorInfo = type.GetConstructor(new Type[] { typeof(...
0
votes
1answer
46 views
C# - how to qualify a static member in object derived through reflection
I'm trying to reference a member of an object of type 'ExternalSourceProvider' that's been instantiated through reflection like this:
Type type = GetProviderType(vendor);
...
1
vote
2answers
244 views
Is it good OOP practice to pass object to object and have more than one instance of class?
Singleton pattern saying "there should be no more than one instance of same class", is this something one should stick to when designing PHP OOP applications?
What are advantages / disadvantages?
...
7
votes
4answers
531 views
What are the responsibilties of the main in object oriented programming?
I'm new to object oriented programming and I don't understand what's the purpose of the main.
Yes, I read that it's the "entry point" of the program but what I don't understand is what should be in ...
0
votes
0answers
26 views
Hierarchical data structure: pull requests + pull request reviews + pull request review comments
GitHub has:
pull requests
pull request reviews
pull request review comments
BitBucket has only:
pull requests
pull request comments
So there are three kinds of objects.
I write code ...
5
votes
4answers
463 views
Does it violate any OOP principle if a member function does not use any of class properties/member variables?
I have an existing class which interacts which can open, read or write to a file. I need to retrieve a file modification for that purpose I have to add a new method
Suppose this following is my ...
-1
votes
1answer
66 views
Classes for integrating both BitBucket and GitHub into our site (an inheritance and composition question)
I am writing a system of callbacks for BitBucket and GitHub which should modify our site on certain events in BitBucket or GitHub.
It is reasonable to make a base class like GitIntegration to handle ...
0
votes
2answers
200 views
How many types of polymorphism are there in the Python language?
I just read an article by Luca Cardelli and he explained types of polymorphism which are:
The article is named On Understanding Types, Data Abstraction, and Polymorphism.
Types of Polymorphism
...
5
votes
2answers
251 views
Separating business logic on code
I have a Category and Product tables in database and classes on project.
Category class has {id, Name} properties
Product class has {id, Name, CategoryId} and other relations.
And I have repository ...
22
votes
10answers
5k views
Is it an anti-pattern if a class property creates and returns a new instance of a class?
I have a class called Heading that does a few things, but it should also be a able to return the opposite of the current heading value, which finally has to be used via creating a new instance of the ...
-2
votes
1answer
168 views
Why do class based languages like c# and java still use files to store code? [closed]
In quite a few object oriented languages, especially the ones without free standing functions, it's now best practice to have one class per file, with the file name being the same as the class name. E....
0
votes
0answers
106 views
Should all classes and interfaces ultimately derive from one Class, and how does this affect type safety?
If I have "Object" as the top level class, then I have various interfaces, ISomething, ISomethingB, ISomethingC, then I have Class x,y,z, all ultimately deriving from the class Object (these ...
-1
votes
0answers
45 views
Representing block of time for course scheduling
I am working on a class scheduling problem. For part of this, I am writing a java class called block that has 2 x 5 array which represents a two hour block which is a block of time for class to be ...
0
votes
1answer
69 views
Hanabi card game: Correctly structuring the deck code
I'm trying to improve my understanding and ability to write code that uses recommended principles and practices, such as the SOLID principles. To do this, I am implementing the fireworks card game ...
5
votes
3answers
100 views
If I have a case with 2 subcases should I use 1 or 2 Use Cases?
Let's say I have this example. There is a chef (actor) and a Use Case cook food. If there are 2 food options to cook (lets say pasta and pizza). Should I create 1 Use Case : CookFood and then in ...
0
votes
3answers
198 views
How and to apply Single responsibility principle correctly? [duplicate]
From Wikipedia on Single responsibility principle SoC
... class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be ...
1
vote
2answers
136 views
How to think in Object Oriented way when it comes to passing messages?
Somewhere I have read that "Object Oriented" is a misnomer and that OO should really stand for "message-oriented programming".
What I am not clear about is ... what does it mean? For example in ...
2
votes
1answer
139 views
Is there a name for a design technique where an object's method takes input and returns custom business object?
What do you call a class that has methods that
take input (from user, from GET or POST)
transform it to a business object and return that object
example ...
class Input
{
function getObject(...
1
vote
0answers
54 views
How to trigger other events in MVC, once the desired event completes?
What is a technique in MVC that can be used to trigger updates?
Namely,
When user clicks a button save a product I have this:
function saveProduct($product)
{
$this->repository->...
-1
votes
1answer
121 views
How to force user to create new instance of object
I have library with asynchronous thread and application who use them. Application can pass object to library of type provide by library interface. If application does not create new instance of object ...
6
votes
9answers
806 views
Are init() methods a code smell?
Is there any purpose for declaring an init() method for a type?
I'm not asking whether we should prefer init() over a constructor or how to avoid declaring init().
I'm asking if there is any ...
1
vote
1answer
82 views
Design a java based menu so that it's easier to add new options
I am trying to create a java console program which displays a Menu with few options. Each option selection performs some independent operation say executing a script or performing some db operation, ...
0
votes
2answers
154 views
Is it bad OOP practice to have any independent procedural code outside of classes definition?
In large PHP OOP application is it bad practice to have procedural
code outside of class definitions i mean that works independently
from objects? e.g. intertwine OOP and Procedural code in same
...
0
votes
2answers
69 views
Keep consistency when items can be in several classes
I'm having a difficulty to figure out relating an item to classes properly.
For example, I have a business directory website that shows profiles of different companies according to the products/...
4
votes
8answers
481 views
Avoiding instanceof vs abstract God Class. Do I have an alternative?
I have a large number of classes with an abstract base class (A) that contains behaviour that must be supported by all the sub classes say [B..I].
In my code, I end up with a collection of objects ...
5
votes
1answer
224 views
How do I structure my code to avoid tight coupling between my parent and child classes?
I'm using a third party product that has a class I can extend to provide a new way for that product to get data (the product is Sitecore but I don't think it's super relevant to the question).
They ...
5
votes
3answers
192 views
How can I generalize multiple distinct classes as a single class, united by purpose?
I have a StringValidator. A StringValidator is either a Regex or a string pattern using '*' wildcards. I want the StringValidator.StringIsValid() to perform one action or a different one, depending on ...
0
votes
3answers
214 views
Why not make everything private or public? [closed]
In code there are private and public declarations. Why shouldn't I make everything private or make everything public?
2
votes
1answer
171 views
Must constructors of value objects not do work, even when class invariants prescribe so?
Today I had a discussion with a colleague.
It is my understanding that a class has the responsibility to ensure that its objects have a valid state when interacted with from outside the class. The ...
4
votes
1answer
74 views
The bound mechanism by generics for a type variable to appear in its own bound
From Programming Languages: Principles and Paradigms
By Maurizio Gabbrielli, Simone Martini
The bound mechanism for type variables is fairly sophisticated and
flexible. In particular, a type ...
6
votes
3answers
311 views
Parameterizing vs property assignment
Today I had a dicussion with a colleague.
I tend to believe that a value in a property should be a meaningful part of the state of an object at any given time. This automatically almost always makes ...
0
votes
1answer
139 views
Is it OK to use class names in an interface definition?
I am creating interface in Java for custom error handler.
Want to pass an argument error object but I need it to be child of Exception class.
Is it okay to use my defined class name in an interface ?...
1
vote
1answer
82 views
Proper way to difference user types in OO
I'm designing an application where I have users and admins (further down in the future, I can have different sub-ranks, where each one can have access to some area of the application).
Currently, I ...
3
votes
2answers
93 views
Is polymorphism appropriate for modeling natural language form (structure), or is there something better?
Let's take French and Japanese adjectives as simple examples.
French adjectives have gender (masculine or feminine) and number (singular or plural), whereas Japanese nouns have neither. However, ...
6
votes
3answers
451 views
Clean code: consequences of short methods with few parameters
Recently during a code review I came across code, written by a new colleague, which contains a pattern with a smell. I suspect that my colleague's decisions are based on rules proposed by the famous ...
3
votes
5answers
451 views
Start Method vs. Setting up everything in constructor
The internal framework my company uses has a pretty pivotal Object that has a pattern of being instantiated as a member of a class with a no argument constructor but to be usable you have to call a ...
0
votes
1answer
58 views
Mutual observer
I want my Wire objects to be in connection with Port objects. That is Port has a list of connected wires and method Port.add(wire). Similarly, Wire has list of ports it is connected to and Wire.add(...
6
votes
8answers
837 views
Why don't constructor return bool to indicate its success or failure without having to throw an exception?
Take C++ constructors for example, we know they don't return values. Why did Bjarne Stroustrup in the beginning decide not to allow constructor returning 'false' to indicate it fails, so that the run ...
0
votes
1answer
69 views
Is this an example of Composition or Aggregation?
I understand the concept behind Composition ('has a') where the contained class is destroyed upon termination of the container class. Likewise, I get Aggregation which is a 'looser' relationship ...
3
votes
5answers
295 views
Design Pattern for interdependent abstract methods
I want to model some mathematical structures. For this purpose I want to define an interface, an abstract class for general purpose algorithms and concrete implementations of that class (I have three ...
4
votes
2answers
337 views
Is it ok to have an empty abstract class to make concrete classes polymorphic
BEFORE:
I have an interface that has one method definition
public interface IDockable
{
void Dock(DockerContainerConfig config);
}
Everything is ok for my first implementation
public class ...
0
votes
0answers
43 views
Use Local Parameters If Global are empty?
Simplified Case with Immutable Class
final class Secret implements IFoo
{
private $header;
public function __construct(array $header = [])
{
$this->header = $header;
}
...
-1
votes
1answer
79 views
abstract classes or other generalization classes?
i have a question about software engineering best practice.
Let's consider a class "User", with 2 subclasses "Student" and "Teacher"
if we need to specify some data for "University special council" ...
4
votes
3answers
136 views
Using Nested Classes for Input and Output to a Calculation Method
We have a large project that performs a lot of modelling and calculations. This code is being broken down into smaller, more manageable chunks, by shifting particular calculations into their own ...