New answers tagged

0

Alright, well I'm an idiot. I was basing this off of logs from PhpStan while performing static analysis. Simply checking if the return value was instance of sub class made it pass. Note to self, always check the simple solutions first.


0

I would say it's a flaw, yes. The issue is that QuizClient::create returns "some type of quiz", not necessarily a LessonQuiz. So if it created a type of quiz that didn't have a lessonId, this code would fail. In fact, in many languages this wouldn't compile at all. Since it looks like you know when you specifically want a lesson quiz, one possibility ...


1

How about One queue per Category of Data? When data comes through it is placed on the appropriate queue. The consumer threads are assigned some group of queues via the map. The consumers can only pull messages off of a queue that they have been assigned. If a consumer wishes to obtain another queue it synchronises with that other thread and they rebalance ...


2

A bit of clarification: A terminal or console is the window where you type the commands, but the shell is the program which interprets and executes the commands. So your question is about implementing a shell. Some commands may be built-in in the shell language, but typically they are just external programs. So if you type "foo", the shell looks in the path ...


1

You can be looking for a shell like: bash, sh, korn, zsh, fish. Roughly speaking,they are languages for interact with the kernel. And those have the ability to support ls, cd... (I don't have a clue, witch one of those should be better to look into the source code) Or you can be looking to make a terminal/console software which it has no relation with ...


4

Robert Brautigan's answer is good and I'm not trying to supplant it, but I did want to add some direct feedback about the reasoning you posted. If subclass B overrides method foo, but does not call base.foo(), it seems like inheritance in that method is broken If that were the case, then it wouldn't make sense for the compiler to not just outirght ...


0

It is important to distinguish between data structures (which are simply a collection of data fields) and objects (which expose behavior without direct access to fields). They both have their uses and you should pick the right one for the job. If you're building a simple CRUD application without any significant behavior, then all you need is data structures ...


1

Using SwiftUI, my implementation would look like the following: protocol Customer { func showBriefSummary() -> AnyView func showFullSummary() -> AnyView } final class BusinessCustomer: Customer { func showBriefSummary() -> AnyView { // return view } func showFullSummary() -> AnyView { // return view } } let customer: ...


1

First thoughts Inheritance is meant for generalisation and specialisation. But a CustomerSummary is not some kind of Customer, nor is a Customer some kind of a CustomerSummary. So forget using inheritance here. Composition would be a better choice: both an IndividualCustomer and BusinessCustomer have a CustomerSummary that can be used for similar ...


2

Objects are not supposed to be bags of data, and your problem comes directly from the object not in control of its data. The object-oriented solution would be to add your specific behavior to your object. One version may look like this: public interface Customer { UIComponent displayFull(); UIComponent displaySummary(); ...potentially other stuff....


4

There is no standard or best practice here. Web applications have different architectures and lifetimes than desktop applications. Web applications tend to create one instance of those services per HTTP request. Reasons for this vary by tech stack. For PHP web applications, the web app is initialized, executed and torn down with each request. Web ...


4

There is a million ways to get inheritance wrong even unintentionally. There is no exhaustive list of things you can check to make sure a subclass behaves well. Even if there was, you can't really force subclasses to do it. And even if you could, the superclass can also change in ways that unintentionally break some subclasses. A better question is, how to ...


2

Analysis of your options: Option 1 is feasible if there is an original somewhere, so that when you discard the graph, you can reload the original state. Option 2 might lead to a missing separation of concerns, with the manager cumulating responsibilities, and having to know more than it should. Option 3 is interesting but might on one side duplicate some ...


2

Expanding on Greg Burghardt amazing answer with a visual aid (and loosely using College Football as an example): public class Association { List<Conference> conferences; } public class Conference { List<Team> teams; List<Season> pastSeasons; Season currentSeason; } public class Season { List<Match> matches; ...


1

What you are doing, is trying to describe the "domain" sort-of independently first. Trying to figure out what contains what, what has what data elements inside, etc. You are wondering whether this model is "good" according to some metric, I guess. Then you mention as an "edit", as an afterthought what this will be used for. Modeling goes exactly the ...


6

It feels like a good number of things are missing, to be honest. A Team has many Players. A Match is played between two Teams. A Season is composed of many Matches. A Season is managed by a SportsAssociation (think: National Basketball League [USA], FIFA, etc...) A SportsAssociation compiles a Team's SeasonRecord A SeasonRecord references a Team and a list ...


-5

Do the classes/objects have data elements or getter/setters and no actual business methods. If yes, immediate red flag, design is probably a database model or some procedural type design. Cyclic dependencies. The amount of technical jargon in class and method names. Ideally none, the more there is, the worse the design probably is. Technical jargon is ...


4

You will not find many design defects in a class diagram itself: The class diagram is a language to communicate about the design. If you’d use English language to communicate about your design, you wouldn’t probably look at the choice of words or the structure of the sentences to find flaws in the reasoning, would you? Moreover the class diagram only shows ...


1

Yes, diagrams can be used to find overall / high level defects in the modeling and design and are sometimes a good base for discussions. Be aware however that design is a highly subjective topic. First, forget the SOLID principles! There are much more usable and practical ways to determine whether a design looks good or not. Here are some mechanical (easy ...


1

Trying to find defects in a design by just using a class diagram, without implementing the classes in code is like trying to find bugs in code without tests. - So don't get me wrong, I am not saying it is completely impossible to find some defects (or "design smells"), but in total it is not very efficient. So yes, one can look at the diagram and review it,...


5

If I pass this object to that constructor, does that new object now have a dependency? Nope. Just 'cause you pass it, that doesn't guarantee it gets used. It might be fine to pass null. To have a dependency means you depend on it. You need it. Now it's true that, mechanically, Dependency Injection is just reference passing with a fancy name. But the idea ...


-1

I would argue that in this particular case, it should be neither. If you require that users have unique usernames, then that is the concern of the database. Any decent database should allow uniqueness constraints, and applying them properly means you will have no issues with race conditions.


1

Literally? Yes, along with the wires and doped silicon. Conceptually? No. Data Structure vs. Object A Data Structure is something your code imposes on a region of memory. While a different region of memory can be passed in, the range of behaviours are not. These are supplied by the reader. Native data types generally are Data Structures: ints, bools, ...


3

In any case, I need a single configuration for the entire application. You can use an external configuration file. You can instantiate multiple configuration objects, which may all simply read from and write to this very file. Therefore, you can obviously have multiple instances but a single set of configuration-related settings. Creating multiple ...


1

That seems to be an interesting challenge indeed. As @DocBrown and you mentioned, make sure to have tests before changing the code. I may be late to the party, but I have a technique for you to set these tests quite rapidly. It's called "Approval Testing" (it has other names like "Golden Master" or "Characterization Tests"). The recipe is: Execute the ...


5

There is a frequent confusion between having only one and must absolutely have only one. While the latter certainly requires a singleton, the former only requires some discipline to create a configuration object and inject it where it is used. If you think that your configuration object must absolutely exist only once, it might probably be because you use ...


1

It all depends on your context and goals and how you see prototyping in your development approach. Basically, yes, it is ok to have a demo prototype with a very light fake or mock database instead of a real one: Iterating though all the "records" is then easy to develop. But of course, it is not very performant. Just make sure that all stakeholders ...


Top 50 recent answers are included