diff --git "a/stack_exchange/SE/SE 2018.csv" "b/stack_exchange/SE/SE 2018.csv" new file mode 100644--- /dev/null +++ "b/stack_exchange/SE/SE 2018.csv" @@ -0,0 +1,110924 @@ +Id,PostTypeId,AcceptedAnswerId,ParentId,CreationDate,DeletionDate,Score,ViewCount,Body,OwnerUserId,OwnerDisplayName,LastEditorUserId,LastEditorDisplayName,LastEditDate,LastActivityDate,Title,Tags,AnswerCount,CommentCount,FavoriteCount,ClosedDate,CommunityOwnedDate,ContentLicense,, +363220,1,,,1/1/2018 3:45,,2,796,"
Is many Levels of multilevel inheritance is considered bad?
+ +This is my design
+ +BaseFileProcessor
+RefundFile Processor inherits BaseFileProcessor (Has n child class)
+FailedRefundFile Processor inherits RefundFile (Has n child class)
+FailedRefundFile for CardsPayment inherits FailedRefundFile (n child class)
+
+",264027,,177980,,43101.36597,43101.39236,Multilevel inheritance with more than three levels,I have a need for a distributed data store, where existing solutions may not work as the computers these will be running on will be extremely resource limited, for instance 64-128MB RAM. Plus, as a fun exercise.
+ +I'm looking at writing a simple implementation of the RAFT algorithm, however the data store, which will simply be a collection of key/values, may have clients updating any of the nodes at any time, and must keep consistency among the entire cluster.
+ +I was thinking of having a node, every time when updated from a client, calculate a hash, then get consensus/confirmation from the other members of the cluster on the old and new hashes and commit, once that is gotten from a majority. Would that ensure orderly updates when two members are updated simultaneously? Any thoughts on implementing this?
+",292185,,9113,,43101.37847,43433.10278,Distributed database algorithm,I have only theoretical knowledge about ESB.
+ +Use case:-
+ +I see both ESB vs Micro-services can fit here theoretically. Both makes the application loosely coupled and scalable instead of single monolithic application. I am not sure what are the +criteria's/attributes I should consider to select off the shelf ESB product(paid or open source ) over disintegrating the app into micro services?
+ +My Understanding :- + ESB can be more fit here as it makes the application more loosely coupled where one component/application will simply put +the message over channel(which is nothing but java object in java based ESB apps on which other components listens). Now other components like routers/transformer/adapters/endpoints etc. will come into picture and take further action. Here Sending component just needs to know the destination +address which will be single channel address.
+ +In case of microservices this is also true, but here consumer need to know URL for each specific operation.
+ +But now a days I have observed most of the folks are preferring micro services over ESB. I think reason can be ESB has its own learning curve/ DSL/ Paid products but micro services is nothing but service is divided in to smaller maintainable restful components. So no learning curve and no paid products.
+",124597,,124597,,43101.40069,43101.42014,Disintegrating monolithic application with Micro services vs ESB approach?,I'm reading Elliotte Rusty Harold's Java Network Programming. In chapter2, I've read the text about makrSupported() method of InputStream class. The author explains that this method is not object oriented. Because the function for checking mark() available is not provided by separated type. How is the design to be more object oriented still supporting mark() and reset() methods?
There is web App_1 which is on dot net while another web App_2 is on java. App_1 need to interact with App_2.
+ +App_1 can be inter or intra company application.
+ +My question is does in general prominent ESB products provides the way dot net application send the dot net specific object/message on channel, then +transformer transform the dot net object to java object and put it on channel_2 like below image
+ + +",124597,,124597,,43101.65764,43101.65764,Dot net and java application connected through ESB?,As mentioned in wiki,
+ +A service-oriented architecture (SOA) is a style of software design where services are provided to the other components by application components, through a communication protocol over a network. The basic principles of service-oriented architecture are independent of vendors, products and technologies. A service is a discrete unit of functionality that can be accessed remotely and acted upon and updated independently, such as retrieving a credit card statement online.
+ +Each SOA building block can play any of the three roles:
+ +Service provider
Service broker
Service requester/consumer
Service-oriented architecture can be implemented with Web services. Ex: Web services based on WSDL and SOAP
+ +A web service implementation talks about exposing POJO with @WebService tag and another implementation talks about exposing those POJO in services.xml.
The client will avail those exposed services over SOAP or REST.
+ +————————
+ +1) Are web services(like Axis2) only option to implement SOA building blocks?
+ +If yes,
+ +2) what are the challenges of conventional middle ware(RMI/CORBA) that web services addressed?
+",131582,,131582,,43103.36806,43103.36806,RMI/CORBA vs Web service,I am building a web/mobile application with Django Rest Framework (DRF) that enables authenticated users to post snippets and/or vote for other user's snippets. All users (authenticated or not) can also get the list of recent snippets (paginated, ex: 5 per page). Snippets, users and votes are stored backend in database.
+ +I'm totally new to serverless architecture so I'm asking the question: is this application a good fit for this kind of architecture? Obviously, my DRF application is built around Web REST APIs which seems to be at first glance a good fit but the authentication part of users and paginated list of snippets let me think it could not be the case.
+ +Can someone enlighten me?
+",292160,,,,,43657.73403,Is serverless architecture a good fit for Django Rest Framework app?,The GoF book ""Design Patterns"" describes the Memento pattern as an object encapsulating its state in a separate object. However, the book specifically describes the memento for use with a specific caretaker; in their example, a undo/redo provider.
However, this pattern, especially in C# when the Memento is made a struct (in both the technical and conceptual senses), can provide many benefits when made a more general part of a class:
We can also use the memento as a kind of implicitly safe to serialize version of the class throughout the application.
+ +However, you could argue, many of the above are just abusing the pattern for the purpose of circumventing language shortcomings.
+ +For example:
+ +public class Computer
+{
+ public Computer(ComputerMemento state)
+ {
+ _state = state;
+ }
+
+ private ComputerMemento _state;
+ public ComputerMemento State
+ {
+ get
+ {
+ var copy = _state;
+ return copy;
+ }
+ }
+
+ public void DoSomeComputerThing() { }
+ public void DoComputerStuff() { }
+ public int GetSomeComputerCalculation() { }
+}
+
+public struct ComputerMomento
+{
+ public string MachineName;
+ public float ProcessorSpeed;
+ public long AmountOfRam;
+ public int CPUCores;
+}
+
+
+The above Computer class can now expose an editable representation of its states while still being able to certify (albeit in an easily circumventable way) that changes to its state (via its methods) are valid and supported. Basically, the consumer can select its desired level of ignorance.
Is this expanded use of what seems to be the memento pattern still the memento pattern? If not, does it have a name?
+ +EDIT: In the above code, since structs are passed by value, the state is immutable by outside classes.
I am creating an ASP.NET MVC website in which I require a number of different sections such as admin, current deliveries, an inventory of products, etc. +Would it be more beneficial, a subdomain for each different section, for example:
+ +admin.mywebsite.com
+
+
+or using this sort of routing:
+ +mywebsite.com/admin
+
+
+Which would be better design?
+",288322,,288322,,43101.84097,43101.86944,Would it be more beneficial to make a subdomain or route in a website?,I'm attempting to figure out if an algorithm currently exists to accomplish what I'm trying to accomplish.
+ +I have a series of time slots over the course of a week where I wish to assign a roughly equal number of people to each time slot during the week. Unlike this question, the time slots are provided as just ranges of hours, and members of the population only need to be pigeon holed in a roughly equally distributed way.
+ +Most of the population has provided a 1st, 2nd and 3rd choice for their desired time slot. People who list a time slot as multiple preferences are considered improperly filled out and the preference will only be considered once and their remaining preferences will be considered as having no preference.
+ +Additionally some of the population may not provide an answer or may say they have no preference. They will still need to be assigned a time slot, but can be assigned whatever time slot is necessary to satisfy the algorithm.
+ +However, the time slots themselves have no preference over who goes where, other than that they want people to be roughly evenly distributed, meaning this is not just a case of the stable-marriage/hospital-resident problem. It further differs from the stable marriage problem in that members of the population do not have a preference for every time slot, which seems to be required for that algorithm to operate.
+ +The objective of the algorithm is as follows (in order of importance):
+ +In my research, I've also found that the stable-marriage problem can have different outcomes depending on which side goes first in their proposals. I hope that the starting state would not affect the outcome of the algorithm, but if necessary I can simply run it many times and take the best result. I would also like to avoid assigning arbitrary constants to preferences unless absolutely necessary.
+ +This is a fairly complex problem so I'm not expecting to get a complete algorithm from here unless one already exists for solving this exact problem. My question is mostly regarding whether there are similar algorithms or areas of study that I should start from. Can anyone help point me in the right direction?
+ +Additionally, am I dismissing the SMP as a starting point incorrectly?
+",117330,,117330,,43101.92361,43252.20486,Algorithm for assigning people to time slots based on preference,I am struggling to fully understand the usage of constructors in Java.
+ +What I have learned so far about constructors is the following:
+ +When for example a string has to be returned from a class that needs to be called then a method could be created, i.e. a constructor will not be sufficient as this will not return anything.
+ +Attempt to answer the question
+ +In order to explain what I mean, I have created a class with two constructors and two methods that return a string.
+ +public class HelloWorldConstructor {
+ public HelloWorldConstructor() { }
+
+ public HelloWorldConstructor(String a) {
+ saySomething(a);
+ }
+
+ public HelloWorldConstructor(String a, String b) {
+ saySomething(a, b);
+ }
+
+ void saySomething(String a) {
+ System.out.println(a);
+ }
+
+ void saySomething(String a, String b) {
+ System.out.println(a + "", "" + b);
+ }
+}
+
+
+Option 1
+ +It is possible to return a string by calling the method that resides in the class.
+ +public class CallConstructor {
+ public static void main(String[] args) {
+ HelloWorldConstructor hwc = new HelloWorldConstructor();
+
+ hwc.saySomething(""allo"");
+ hwc.saySomething(""allo"", ""allo"");
+ }
+}
+
+
+returns:
+ +allo
+allo, allo
+
+
+Option 2
+ +It is also possible to return a string by calling the constructor directly.
+ +public class CallConstructor2 {
+ public static void main(String[] args) {
+ new HelloWorldConstructor(""allo"");
+ new HelloWorldConstructor(""allo"", ""allo"");
+ }
+}
+
+
+returns the same as option 1.
+ +Discussion
+ +When option 2 is chosen, then two objects have to be created instead of one as depicted by option 1, but when to choose option 2 and when option 1? In this case I think it is better to choose option 1 as one object will be created, but option 2 could be suitable when other circumstances are applicable.
+ + + +++ +The constructor in the example just gives an initial value to class + members.
+
https://stackoverflow.com/a/19941847/2777965
+ +++ +Constructors are used to initialize the instances of your classes. You + use a constructor to create new objects often with parameters + specifying the initial state or other important information about the + object
+
After reading about theory and Q&As about constructors I am struggling to fully understand them. I know how to call a constructor and how to call a method, but I cannot rationalize this.
+ +Let’s say I have an object, called “Tile”, which has both a name and a list of directions. We’ll assume that each tile has a 3x3 grid of pixels, which can either be on or off. The middle center pixel (designated with a “N” in the diagram) of the tile turns on when the North direction is “True”. The center left pixel (“W” in the diagram) of the tile turns on when the West direction is “True”. The center right pixel (“E”) of the tile turns on when the East direction is “True”. The bottom center pixel (“S”) of the tile turns on when the South direction is “True”. The middle pixel (“C”) is always on.
+ +Diagram:
+ + N
+WCE
+ S
+
+
+Each tile can only have one start and end, so there are 6 possible tiles. (Straights East-West and North-South, and all 4 turning pieces which form 90 degree angles)
+ +Here’s an example tile, complete with attributes:
+ +Tile1:
+-North: True
+-East: False
+-South: False
+-West: True
+
+
+Here’s what that tile looks like, if dashes are “off” pixels and percent signs are on pixels:
+ +-%-
+%%-
+——-
+
+
+Let’s say I have a list of these tiles, where each tile connects to the one in the list before it, and I am procedurally generating them.
+ +The idea is to be able to generate paths of arbitrary lengths, which do not need to exist inside the bounds of an array.
+ +Of course, I want my map of tiles to be logically sensible, so it cannot have more than 3 lefts or rights in a row. My current “solution” is to have a counter where I subtract one if it turns to the right of the current tile, and add one if it turns to the left. I could then force it to choose a left-turning piece if the counter is at -3, and force it to choose a right turning piece if the counter is at 3. (This algorithm will work with my current generation methods, that is not the problem.)
+ +What is the most efficient way, given the past tiles and their respective directions, to determine whether to increment or decrement the counter?
+ +Sorry if this is a little verbose, I couldn’t think of a better way to phrase my question.
+ +Edit: +To clarify, the goal of the algorithm is to determine whether a tile given turns left, right, or straight (which isn’t really a turn, but IDC) based on the previous tiles and return 1, -1, or 0, respectively. That’s it.
+",292228,,292228,,43101.99444,43102.02222,Algorithm to determine direction based on previous tiles,As described here, a function can be said to be a query when it returns a value, and a command when it modifies a value. It also states that a function should not be both.
+ +That a query should not be a command seems popularly enforced by functional programming, in that it is a pure function.
+ +Does a language exist, where if and only if the function is non-void, it cannot change state?
+",212623,,113256,,43104.78056,43320.80208,Has any language enforced Command–query separation?,I have a website built on PHP, and now I want users to be able to log in. I do not want to take care of user management myself, so I'm thinking that social sign in would be convenient both for myself and for the users. The website is a traditional ""server rendered"" site, i.e. I have a database on my server, and my PHP-scripts need some form of user authentication/user id in order to insert and retrieve stuff from the database.
+ +I have used Firebase auth and FirebaseUI for ""client side"" websites before, which is really nice since they take care of everything, including the UI and login flow.
+ +But when it comes to using it for a traditional ""server-side"" application, I'm confused. I guess I can use FirebaseUI on the browser to get the user to sign in and retrieve a JWT token, but then what? How would I pass it to the server scripts on each request? Or should I just pass it once and start a session based on the information in the JWT token? Or should I use something entirely different?
+",120703,,,,,43945.2125,How to use social sign in with my PHP website?,I'm specifying an API for a REST service. The REST service will be primarily accessed by web browsers using XHR requests running code hosted from remote origins. Therefore, I'll need to add CORS support, such as the Access-Control-Allow-Origin header to allow for XSS.
Should I add CORS headers to non-200 responses, such as 400, 401 and 5xx?
+",148189,,,,,43102.44306,CORS headers for non-200 HTTP responses,If I have a custom type (or maybe an enum) like for ex. a Range:
Public Class Range
+
+ Sub New(minimum As Single, maximum As Single)
+ Me.Minimum = minimum
+ Me.Maximum = maximum
+ End Sub
+
+ Public Property Minimum As Single
+ Public Property Maximum As Single
+ Public ReadOnly Property Delta As Single
+ Get
+ Return Maximum - Minimum
+ End Get
+ End Property
+End Class
+'-----------
+'Some methods...
+
+
+This type should be used in the domain model(implementing DDD), in the business logic when doing stuff and also in the data layer, where it will be stored as a complex type.
+ +So :
+ +App.Common and reference this assembly everywhere (my choice for now, but don't know if having references in domain model project is an anti-pattern?)EDIT
+In my case I use range as a MeasuringRange for measure devices. For ex. a thermometer that can measure from 0°F-250°F:
public class Thermometer
+{
+ public Thermometer(Range measureRange)
+ {
+ this.MeasureRange=measureRange;
+ }
+
+ public Range MeasureRange {get;set;}
+}
+
+
+At the moment it's also used in the DataLayer (using EF Code First) to store the device range as a complexType (EF creates fields MeasureRange_Max and MeasureRange_Min.
It's also used in services in the BLL when doing some measurements with the devices.
+",267308,,267308,,43102.60694,43102.60694,Which layer for custom type (DDD),The Steam Client application allows one to download games purchased through the associated Steam account. A typical modern game uses quite a bit of disk space (in the order of 50-70 GB), so it is not unusual for users to download the files in several Steam sessions.
+ +However, when resuming a download that has been stopped or paused, it resumes almost instantaneously from where it was stopped before. This indicates that no partial hashing is performed on the local machine (which would actually take a lot of time in order to hash tens of GB). How can Steam ensure the integrity of the files if it does not compute a partial hash when resuming the data transfer? Note that even when the download is interrupted due to a system failure, the process resumes almost immediately when the Steam Client is started.
+ +Even if Steam performs a partial hash ""by blocks"", i.e., by hashing the last block instead of the entire file, how can it make sure that the files already on disk are indeed there, or not corrupted?
+",150590,,,,,43102.86389,How does Steam resume downloads without computing a partial hash?,I noticed a pattern in my code. It applies to situations where things can be selected. It revolves around classes which I call (and in code often suffix with) Registry, Slot and Updater.
+ +This class is pretty much a combination of what is known as the registry pattern: (""A well-known object that other objects can use to find common objects and services."") and some filter methods.
+These are supposed to be the list of all [Type]s. They always use a collection internally, but the methods they have is determined by what other classes want from them. That might be simple wrappers for the collection class or domain specific, named filter methods. Events - for example when an item is removed - are added pragmatically when needed.
public class ProductRegistry
+{
+ private readonly List<Product> _products = new List<Product>();
+
+ public void Add(Product product)
+ {
+ _products.Add(Product product)
+ }
+
+ public List<Product> GetAllProductsOnSale()
+ {
+ // domain specific filtering...
+ }
+}
+
+
+Named ""Slot"" because it can hold an object. In most cases, an object being held here means it is the currently selected object. Contrary to Registry and Updaters, the code for this is always the same except for the type of what is being selected. I could turn this into a generic class, but I only came to think of that while writing this question - and it's not like that would change how this pattern works.
+ +public class ProductSlot
+{
+ public event Action WhenProductHasBeenChanged;
+
+ public Product Product{get; private set;}
+
+ public void Set(Product product)
+ {
+ Product = product;
+ if(WhenProductHasBeenChanged!=null) WhenProductHasBeenChanged();
+ }
+}
+
+
+These update the registry and slot. How they achieve that varies wildly, so example code wouldn't make sense here.
+However, to give an example of what they do, a ProductUpdater might supervise the process of downloading a string from a web address, parsing it into Products and then add those to the ProductRegistry.
+One thing I did repeatedly was registering an Updater to the change event of a slot for a different thing. For example, a ContractSlotUpdater listens to changes in a CustomerSlot, so it can update the ContractSlot with the Contract which corresponds to the new Customer.
I added the C# tag because that is the language - and thus the language features - that I am currently using. I see no problem transferring this concept to other languages as long as they have the necessary features.
+ +If this is not a good thing to do, please tell me why.
+Otherwise, I would like to know what to call it.
I have a Aggregate Roots that use the event sourcing technique of being built from a series of events in a Repository. This is all great for when I just need to manage change of state etc, but when I come to using the Specification pattern to apply my app specific business rules, I am hitting a wall on what Entities to use, how to instantiate them etc etc.
+ +I would want to run specific methods on my Repository, for example getProductByProductCode so I can check my current AR against it for uniqueness (simple example), but I am unsure how to do this, as my Repository is set up to get ARs by their ID from the event store.
I used to have a database backing my Repositories, now I only have an event store as I have no read models yet.
+ +I am so confused as I thought I was doing it all the right way now as we need event sourcing, but I can't seem to marry up my old-school thinking with how to do it now it's event sourced :(
+",208446,,,,,43102.75208,Using Event Sourced Aggregate Roots with the Specification Pattern,I've been studying DDD and I'm currently struggling to find a way to apply the concepts in actual code. I have about 10 years of experience with N-tier, so it's very likely that the reason I'm struggling is that my mental model is too coupled to that design.
+ +I've created an Asp.NET Web Application and I'm starting with a simple domain: a web monitoring application. Requirements:
+ +My doubts concern mainly the division of responsibilities, finding the proper place for each thing (validation, business rule, etc). Below, I've written some code and added comments with questions and considerations.
+ +Please criticize and advise. Thanks in advance!
+ +DOMAIN MODEL
+ +Modeled to encapsulate all business rules.
+ +// Encapsulates logic for creating and validating Url's.
+// Based on ""Unbreakable Domain Models"", YouTube talk from Mathias Verraes
+// See https://youtu.be/ZJ63ltuwMaE
+public class Url: ValueObject
+{
+ private System.Uri _uri;
+
+ public string Url => _uri.ToString();
+
+ public Url(string url)
+ {
+ _uri = new Uri(url, UriKind.Absolute); // Fails for a malformed URL.
+ }
+}
+
+// Base class for all Aggregates (root or not).
+public abstract class Aggregate
+{
+ public Guid Id { get; protected set; } = Guid.NewGuid();
+ public DateTime CreatedAt { get; protected set; } = DateTime.UtcNow;
+}
+
+public class WebApp: Aggregate
+{
+ public string Name { get; private set; }
+ public Url Url { get; private set; }
+ public string Version { get; private set; }
+ public DateTime? VersionLatestCheck { get; private set; }
+ public bool IsAlive { get; private set; }
+ public DateTime? IsAliveLatestCheck { get; private set; }
+
+ public WebApp(Guid id, string name, Url url)
+ {
+ if (/* some business validation fails */)
+ throw new InvalidWebAppException(); // Custom exception.
+
+ Id = id;
+ Name = name;
+ Url = url;
+ }
+
+ public void UpdateVersion()
+ {
+ // Delegates the plumbing of HTTP requests and markup-parsing to infrastructure.
+ var versionChecker = Container.Get<IVersionChecker>();
+ var version = versionChecker.GetCurrentVersion(this.Url);
+
+ if (version != this.Version)
+ {
+ var evt = new WebAppVersionUpdated(
+ this.Id,
+ this.Name,
+ this.Version /* old version */,
+ version /* new version */);
+ this.Version = version;
+ this.VersionLatestCheck = DateTime.UtcNow;
+
+ // Now this eems very, very wrong!
+ var repository = Container.Get<IWebAppRepository>();
+ var updateResult = repository.Update(this);
+ if (!updateResult.OK) throw new Exception(updateResult.Errors.ToString());
+
+ _eventDispatcher.Publish(evt);
+ }
+
+ /*
+ * I feel that the aggregate should be responsible for checking and updating its
+ * version, but it seems very wrong to access a Global Container and create the
+ * necessary instances this way. Dependency injection should occur via the
+ * constructor, and making the aggregate depend on infrastructure also seems wrong.
+ *
+ * But if I move such methods to WebAppService, I'm making the aggregate
+ * anaemic; It will become just a simple bag of getters and setters.
+ *
+ * Please advise.
+ */
+ }
+
+ public void UpdateIsAlive()
+ {
+ // Code very similar to UpdateVersion().
+ }
+}
+
+
+And a DomainService class to handle Creates and Deletes, which I believe are not the concern of the Aggregate itself.
+ +public class WebAppService
+{
+ private readonly IWebAppRepository _repository;
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IEventDispatcher _eventDispatcher;
+
+ public WebAppService(
+ IWebAppRepository repository,
+ IUnitOfWork unitOfWork,
+ IEventDispatcher eventDispatcher
+ ) {
+ _repository = repository;
+ _unitOfWork = unitOfWork;
+ _eventDispatcher = eventDispatcher;
+ }
+
+ public OperationResult RegisterWebApp(NewWebAppDto newWebApp)
+ {
+ var webApp = new WebApp(newWebApp);
+
+ var addResult = _repository.Add(webApp);
+ if (!addResult.OK) return addResult.Errors;
+
+ var commitResult = _unitOfWork.Commit();
+ if (!commitResult.OK) return commitResult.Errors;
+
+ _eventDispatcher.Publish(new WebAppRegistered(webApp.Id, webApp.Name, webApp.Url);
+ return OperationResult.Success;
+ }
+
+ public OperationResult RemoveWebApp(Guid webAppId)
+ {
+ var removeResult = _repository.Remove(webAppId);
+ if (!removeResult) return removeResult.Errors;
+
+ _eventDispatcher.Publish(new WebAppRemoved(webAppId);
+ return OperationResult.Success;
+ }
+}
+
+
+APPLICATION LAYER
+ +The class below provides an interface for the WebMonitoring domain to the outside world (web interfaces, rest api's, etc). It's just a shell at this moment, redirecting calls to the appropriate services, but it would grow in the future to orchestrate more logic (accomplished always via domain models).
+ +public class WebMonitoringAppService
+{
+ private readonly IWebAppQueries _webAppQueries;
+ private readonly WebAppService _webAppService;
+
+ /*
+ * I'm not exactly reaching for CQRS here, but I like the idea of having a
+ * separate class for handling queries right from the beginning, since it will
+ * help me fine-tune them as needed, and always keep a clean separation between
+ * crud-like queries (needed for domain business rules) and the ones for serving
+ * the outside-world.
+ */
+
+ public WebMonitoringAppService(
+ IWebAppQueries webAppQueries,
+ WebAppService webAppService
+ ) {
+ _webAppQueries = webAppQueries;
+ _webAppService = webAppService;
+ }
+
+ public WebAppDetailsDto GetDetails(Guid webAppId)
+ {
+ return _webAppQueries.GetDetails(webAppId);
+ }
+
+ public List<WebAppDetailsDto> ListWebApps()
+ {
+ return _webAppQueries.ListWebApps(webAppId);
+ }
+
+ public OperationResult RegisterWebApp(NewWebAppDto newWebApp)
+ {
+ return _webAppService.RegisterWebApp(newWebApp);
+ }
+
+ public OperationResult RemoveWebApp(Guid webAppId)
+ {
+ return _webAppService.RemoveWebApp(newWebApp);
+ }
+}
+
+
+Closing the Matters
+ +After gathering of answers here and in this other question, which I opened for a different reason but ultimatelly got to the same point as this one, I came up with this cleaner and better solution:
+ +Solution proposition in Github Gist
+",20115,,20115,,43104.45903,43104.45903,How to apply some concepts of DDD to actual code? Specific questions inside,I see size of boolean is not defined. Below are two statements I see at java primitive data size
+ +++ +not precisely defined
+
Further explanation says
+ +++ +boolean represents one bit of information, but its ""size"" isn't + something that's precisely defined.
+
Question came to my mind was why boolean in java can't be represented with 1 bit(or 1 byte if byte is minimum representation ) ?
+ +But I see it has been already answered at https://stackoverflow.com/questions/1907318/why-is-javas-boolean-primitive-size-not-defined where +it says
+ +++ +the JVM uses a 32-bit stack cell, used to hold local variables, method + arguments, and expression values. Primitives that are smaller than 1 + cell are padded out, primitives larger than 32 bits (long and double) + take 2 cells
+
Does it mean even byte/char/short primitiva data types also take 32 bit though their size is defined as 8/16/16 bit ?
+ +Also can we say boolean size will be 32 bit on 32 bit cpu and 64 bit on 64 bit cpu ?
+",124597,,124597,,43102.70208,43103.04931,boolean size not defined in java: why?,I'm learning about OOD and good practices in OOP and find myself struggling with some key concepts. As a practice I'm rewriting my custom PDO database abstraction layer which used to be a single file class with >2000 lines of code.
+I learned one should use inheritance if classes are in a "is an" relationship and composition if they have a "has a" relationship. Composition can be implemented as this, given that I would avoid php's traits (example from here):
<?php
+
+class Head {
+}
+
+class Human {
+ private $head;
+ public function __construct(Head $head) {
+ $this->head = $head;
+ }
+}
+
+$bob = new Human(new Head);
+
+Good. However, in my case I want to composite a class B to A, while there can be multiple instances of B. Precisely, the main database class (A) has one or multiple table classes (B). Injecting a table object similar to the head object in the above example might be not what I want. Later, there might be also maybe a select class or a insert class. I do this just for practice and learn how I can keep my classes small in file size. Should I all inject all dependencies during construction and recylcle them? Or should I instantiate them within the main database class and inject the connection to the subclasses. The main database class holds the PDO object in '$_connection'.
database and table.I can think of these strategies.
+<?php
+
+class db extends PDO{
+
+ private $_connection;
+
+ public function __construct($dsn){
+
+ $this->_connection = new parent::__construct($dsn);
+
+ }
+
+ public function createTable($def){
+
+ $table = new Table(this->_connection, $def);
+
+ }
+
+}
+
+Cons:
+new operator in a method which I assume is generally not ideal. Better, I should inject all instances.createTable method in the base class. This spams my base class. If functionality increases the base class will be bigger and bigger, which is what I wanted to circumvent in the first place. I would rather like to be able to call create on the table object as in Table->create().<?php
+
+class db extends PDO{
+
+ private $_connection;
+ public $table;
+
+ public function __construct($dsn, $table){
+
+ $this->_connection = new parent::__construct($dsn);
+ $this->table = $table;
+
+ }
+
+}
+
+$db = new db($dsn, new $Table)
+$db->table->create($def);
+
+Cons:
+connection available in the Table class as it is neither a child nor is the connection manually injected.I don't think the db and Table classes are in a "is a" relationship and thus should not be inherited from each other. But currently I'm lacking a good composition implementation.
+Disclaimer
+I tried to work for a solution but need help on what could be the best practice for this. Composition, as posted with the example (human, head), just doesn't feel right here in the case of database and table. I hope I'll receive helpful answers, also links or buzz words are welcome as I'm just learning and I seem to have a hard time to enter the next level.
+",292274,,-1,,43998.41736,43102.97014,php class composition: how to implement “has a” relationship in the case of a DAL,I have a search box I'm going to use on different pages (I use the term 'page' loosely here).
+ +Example state:
+ +{
+ searchString: 'Cheeeese',
+ results: [
+ 'I like Cheeeese!',
+ 'There is no Cheeeese!!',
+ ],
+}
+
+
+What's baffling me is this - if there are multiple search boxes (on different 'pages') where do I put the responsibility for requesting the results from the API?
+ +The nearest thing to sanity I can find is a non-rendering component whose sole purpose is to watch the searchString state entry, and fire off a request to the API (updating results on response).
Is this a reasonable approach, or is my component structure itself the problem?
+",3526,,,,,43106.35417,How should I structure React Redux components when requesting Data From an API?,Sometimes my Aggregate will be very simple; some scenarios are simply not complex enough to require deep trees of objects and relations.
+ +Consider a Website Monitoring application, which periodically pings a URL to check if it is alive.
+ +The Web App will have:
+ +It doesn't have much data, doesn't have child objects (except maybe for URL being a Value Object) and will certainly not have much invariants - if any - to enforce either, at least not at this time.
+ +Now some say that because it is not modelling a more complex model, with relationships and internals and whatnot, it is not an Aggregate, it is only an Entity.
+ +The thing is, I don't think that complexity or size should be dictating if it's an Aggregate, Entity or Value Object, but rather its MEANING.
+ +For the Web Application Monitoring domain, that Web App ""entity"" is the root model, it's what is going to be returned from a Repository. If the domain expert brings new requirements, they will be related to that Web App model.
+ +So, for me, I believe it makes it a WebAppAggregate, rather than a WebAppEntity.
+ +Question: is my line of thinking correct, or did I get it all wrong? Thanks in advance.
+",20115,,,,,43103.59583,"DDD: must all Aggregates model relationships, or they can be ""shallow""?",Whenever I need division, for example, condition checking, I would like to refactor the expression of division into multiplication, for example:
+ +Original version:
+ +if(newValue / oldValue >= SOME_CONSTANT)
+
+
+New version:
+ +if(newValue >= oldValue * SOME_CONSTANT)
+
+
+Because I think it can avoid:
+ +Division by zero
Overflow when oldValue is very small
Is that right? Is there a problem for this habit?
+",248528,,591,,43105.64861,43647.32639,Is it good practice to replace division with multiplication when possible?,