Тёмный

SOLID Principles? Nope, just Coupling and Cohesion 

CodeOpinion
Подписаться 85 тыс.
Просмотров 32 тыс.
50% 1

How do we avoid writing spaghetti code so our systems don't turn into a hot mess? For me Coupling and Cohesion. Some people focus on things like SOLID principles and Clean Architecture. While I don't necessarily have a problem with that if you're pragmatic, I don't ever really think about either of those explicitly.
🔗 EventStoreDB
eventsto.re/codeopinion
🔔 Subscribe: / @codeopinion
💥 Join this channel to get access to source code & demos!
/ @codeopinion
🔥 Don't have the JOIN button? Support me on Patreon!
/ codeopinion
📝 Blog: codeopinion.com
👋 Twitter: / codeopinion
✨ LinkedIn: / dcomartin
📧 Weekly Updates: mailchi.mp/63c7a0b3ff38/codeo...
0:00 Intro
1:05 Coupling & Cohesion
3:22 Highly Cohesive Boundary
8:20 Loose Coupling
10:09 Technical Concerns
#softwarearchitecture #softwaredesign #codeopinion

Наука

Опубликовано:

 

1 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 80   
@maxkomarow
@maxkomarow 2 года назад
Thanks man. You've just organized a lot of mess that i've been struggling with after learning about solid, clean architecture, ddd and some other stuff. I think its important to dig through those concepts to not only to understand what they are, but why they are. And from understanding those underlying core things that drive everything else, you can gain a lot of understanding of what to do when and why
@CodeOpinion
@CodeOpinion 2 года назад
You just described why I created this channel and what I try to post videos about!
@gds03_
@gds03_ 2 года назад
I would wish to know developers more like you. Pragmatic and specially avoid complexity. Sometimes what we need to do is so basic, and it seems we are building a spaceship for nothing. And then in the end don't even is able to take off..
@timidboy02
@timidboy02 2 года назад
Great video! I would really love to hear your take on testing as well, unit testing, integration testing, TDD, etc. 😀
@marna_li
@marna_li 2 года назад
I think you touched a point there. SOLID and Clean Architecture both encompass several principles. Buzz words, mostly. The terms are a ways to codify and popularize these principles. There is a lot of opinionated stuff besides that and a lot of “templates”. But once you understand coupling and cohesion from a pragmatic perspective then you can order your stuff around however you want since you understand how to handle complexity.
@CodeOpinion
@CodeOpinion 2 года назад
Yup. There's many different approaches you can take if you narrow it down to coupling and cohesion
@Parthibansekar87
@Parthibansekar87 Год назад
I often hear people saying SRP means doing only one thing. You have clearly explained what that one thing should be. Great video! Thanks!
@Nots88
@Nots88 3 месяца назад
Thanks, actually coupling and cohesion are part of GRASP which in my opinion is more practical and applicable for modern architecture than SOLID.
@Mark73
@Mark73 7 месяцев назад
I love the idea of Coupling and Cohesion so much more than SOLID. It's so much simpler and more elegant. I would add one more "C" to it, though. 'Continuity". Functionality should never break after you make a change. You can overload functions and add optional parameters, but old method signatures should continue to work and work the same way.
@MrSpyTubes
@MrSpyTubes 2 года назад
Thanks for your insights. You have bold statements but always reasonable. I really appreciate your labor for sharing your experience
@CodeOpinion
@CodeOpinion 2 года назад
Thanks, appreciate the comment. I don't think of them as bold or have any intent of being against the grain for views or whatever. Just speaking what I think.
@splendorman7922
@splendorman7922 2 года назад
dudeeeee thanks for awesome video. It is so much clear now. I've been trying to get my head around this topic for the last 2 weeks.
@CodeOpinion
@CodeOpinion 2 года назад
Glad it helped.
@cccc7006
@cccc7006 Год назад
great content, i'll incorporate this approach into my designs
@archmad
@archmad 2 года назад
this what i similarly do in the frontend. group to features, shared uis/utilities and data. Then inside a feature, will have all my codes, may also have shared folders within
@Aalii6
@Aalii6 Месяц назад
very helpful, thank you! 👍👍
@vindecode5837
@vindecode5837 2 года назад
do you have top 10 books that you can recommend ? would love to hear from you 🙂
@CodeOpinion
@CodeOpinion 2 года назад
Good suggestion for a video!
@CodeOpinion
@CodeOpinion 2 года назад
I do and don't. The blue DDD book is one but hard to digest. I've been more into certain individuals perspectives and conference talks.
@pooya72
@pooya72 2 года назад
@@CodeOpinion that would be interesting to hear!
@anthonylevine8783
@anthonylevine8783 2 года назад
@@CodeOpinion It would be pretty interesting to see a video from you about talks, books, blogs, etc. that you have found useful and learn form.
@lizard450
@lizard450 Год назад
I like clean code. It really instilled in me the importance of sticking to my guns and taking some extra time to making things better than when I found them.
@ali-celebi
@ali-celebi 2 года назад
Super useful. Great video.
@CodeOpinion
@CodeOpinion 2 года назад
Glad it was helpful!
@leaoaugusto
@leaoaugusto Год назад
Thank you for the the video.
@ReViv4L
@ReViv4L 11 месяцев назад
I do believe most people build simple apps that do not require any coupling fighting. But then, once you start trying to write an app that implements business processes, you need to start thinking about behavior, events, and coupling. Even though I had my fair share of experience, I enjoyed this vid. Great work.
@CodeOpinion
@CodeOpinion 11 месяцев назад
Glad you enjoyed it. Ya, I don't really know what "most" people are building. When building LOB type systems, in my experience they are fairly large and often end up in less than an ideal place, primarily because of lack of cohesion and almost no concern for coupling.
@MiningForPies
@MiningForPies 2 года назад
Great video as always
@CodeOpinion
@CodeOpinion 2 года назад
👍
@shahrazkl
@shahrazkl 2 года назад
this is great thanks!
@sathyajithps013
@sathyajithps013 2 года назад
Long time no see. Nice video
@emanueltrandafir8756
@emanueltrandafir8756 Год назад
Hello, thanks for the video, the content is great and super usefull! Though, i still believe the solid Principles are quite usefull. I believe that, at a deeper level, they are all about coupling and coehision. For example, you have already mentioned s.r.p. Then, o.c.p encourages polymorphism and dependency inversion, Therefore allowing various implementations to stay in different modules or services rather than putting them into the same place. Also, i.s.p. can be understood as "you should only depend on what you need". Breaking the interfaces into smaller ones is also something that will lead to a higher coehision of the respective component.
@CodeOpinion
@CodeOpinion Год назад
I think they can be a guide, but unfortunately without understanding the root issue (coupling & cohesion), they turn into "rules" and people fail to be pragmatic and understand the tradeoffs.
@inaccessiblecardinal9352
@inaccessiblecardinal9352 5 месяцев назад
Good stuff.
@timmetcalfe5541
@timmetcalfe5541 2 года назад
Very good advice. Your video makes it obvious that focusing on entities so much is the wrong approach.
@joaodasilva2175
@joaodasilva2175 2 года назад
Focusing on 'entities' should not be thought of as 'wrong'. Derek is probably trying to direct people to focus on certain aspects of a solution at certain levels of exposure. For example, if defining a public/private API to the business, this is where consumers of this service will rather see endpoints that make sense to them, so more in tune with their 'business needs' or their 'business workflows'. So that's one level. That layer will obviously at some point need to interact with data, and maybe you have a company policy where abstracting access to the underlying data-source needs to be forbidden or tightly controlled, and therefore, engineers would need to build a mechanism to expose 'entities' that represent the underlying source, and this is the fine-grained/micro level. Generally public facing API's should be more 'capability' driven and not needlessly 'data/entity' driven. Having said all this, when you look at Microsoft D365 OData API, they have ZERO capability level API's, they are all ENTITY based, at least from and endpoint pespective the terms are all 'entities'. So I gues it all depends on the type of thing you're building, and what type of consumer you are focusing on. :-)
@timmetcalfe5541
@timmetcalfe5541 2 года назад
@@joaodasilva2175 Good point Joao. My comment was overly simplistic in hindsight. Thanks for the comprehensive reply.
@LxQP92
@LxQP92 Год назад
5:07 Assume my UI has Name, Price and Quantity which an user can initially define when creating a new product. Is the UI required to send the Create request to each Service? My idea was to only provide a Create REST Endpoint within the Catalog module and internally using Domain and Integration Events like ProductCreated which then can be consumed by Warehouse for example. But this approach would require the Catalog Module to pass the quantity within the ProductCreated event. How could one avoid this?
@mattgraves3709
@mattgraves3709 11 месяцев назад
Outstanding
@michaelstewart6358
@michaelstewart6358 Год назад
Hi Derek! When you split your product entity to support different capability centric services, do you still keep one table on the database or you split it there too ? Can I have different aggregate roots or entities from the same table ? 🤔
@CodeOpinion
@CodeOpinion Год назад
Yes. So as long as your making that distinction and are aware that your logical separation is different than the physical storage. They don't need to be the same, so yes.
@nikhilgoyal007
@nikhilgoyal007 Год назад
Stellar!!!
@coderider3022
@coderider3022 Год назад
I do proper solid with my C# and have done for many years. I get told …. ‘Nobody likes an uncle bob’ by those that wrote the most awful code I’ve seen in my 25yrs
@RasmusSchultz
@RasmusSchultz 2 года назад
7:12 why are "Models" not organized under "Features" with the features that they belong to? (is the model as a whole separate from features for design reasons? for example, I'm wondering if e.g. Checkout might also need access to the ShoppingCart and maybe that's why? do you generally keep the model separate from the features, even if the codebase is organized by feature?)
@CodeOpinion
@CodeOpinion 2 года назад
Often they are shared between various features, but a very limited subset that are related. Eg, Adding, Removing, Updating items, and Checking out a shopping cart all require the shopping cart.
@SimonLiSeeking
@SimonLiSeeking 2 месяца назад
Design pattern is similar. Just couple and cohesive.
@yousef.a.k3793
@yousef.a.k3793 2 года назад
First, Thanks for yours video. But I have question, the Product table is one-to-one relationship, my question is what about the performance? what about multi joins? I started use yours way in my monolith project.
@yousef.a.k3793
@yousef.a.k3793 2 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-DjZepWrAKzM.html and I saw this video from you, and you didn't put the part 2 😅😅, How can we compose and retrieve the data from it. If you can help me. Thanks
@CodeOpinion
@CodeOpinion 2 года назад
The example is simplistic but to illustrate that different boundaries care about different data depending on the behaviors they provide. Each boundary would own the schema and data and provide a means through an API/contract. I wouldn't integrate via the database (eg, joins).
@viktorasmickunas2527
@viktorasmickunas2527 2 года назад
Really makes sense. There's only one thing that bothers me: sometimes you have to distribute code that could be part of one class to separate classes just to be able to unit test them (move them from the private methods of the original class to the public ones of a new class). In one sense it lowers cohesion and creates a new coupled class with the functionality that would benefit from being in one cohesive unit, on the other hand this makes functionality a lot more unit testable. Or is this more about micro service boundaries? What's your take on this?
@CodeOpinion
@CodeOpinion 2 года назад
I kind of know what you're referring to but I don't really do much of moving private to public etc. for testing purposes. Having multiple types isn't a problem as it's about grouping them together in the right place.
@Fred-yq3fs
@Fred-yq3fs 7 месяцев назад
@@CodeOpinion Sometimes you'll have a lot of branching happening in those private. That makes testing particularly difficult for 2 reasons: 1) it might be a lot of work to setup inputs so a given branch is explored, and 2) the exponential explosion of branches. If you decouple by injecting dependencies then you can test the branches independently, avoiding the exponential explosion and simplifying test setup. The problem is now you have lots of mocks, so your tests are coupled to the implementation. So there is a balance there too. Branches often are a sign an endpoint tries to do too much, but eh sometimes you can't ask your client(s) to change their code just to simplify yours. You have to contend with the contracts as they are: full of bells and whistles, options, bools, nullables = branches galore.
@GeekOverdose
@GeekOverdose Год назад
Is your capability approach in stark contrast to Data Oriented Programming?
@David-rz4vc
@David-rz4vc 2 года назад
Do you have a course on how to implement the feature base architecture u mentioned in the vid?
@CodeOpinion
@CodeOpinion 2 года назад
Not yet!
@petermanger9047
@petermanger9047 2 года назад
I think the real value of SOLID and the like is simply to help talk around Coupling and Cohesion - especially with junior coders who seem to really struggle with this concept at an enterprise level.
@CodeOpinion
@CodeOpinion 2 года назад
Used as a guide they can be helpful. But if you don't understand the underlying reason they exist it turns into a pissing match. The number of times I get "but doesn't this violate X principle?" is pretty interesting.
@petermanger9047
@petermanger9047 2 года назад
@@CodeOpinion Totally. Context matters!
@akashagarwal6390
@akashagarwal6390 5 месяцев назад
is it same as DDD? also we seem to essentially end up in the microservices world right?
@CodeOpinion
@CodeOpinion 5 месяцев назад
Not entirely. DDD has strategic and tactical patterns that ultimately are adressing coupling and cohesion. Almost everything resolves around them at the core.
@liftingisfun2350
@liftingisfun2350 2 года назад
my name is codeopinion and i love async messaging a lot
@CodeOpinion
@CodeOpinion 2 года назад
Accurate
@macieks3604
@macieks3604 Год назад
how about simple code example illustrating the point. There is too much spaghetti definitions of coupling and cohesion online, what we need it cohesive and decoupled explanation which we can transfer and apply elsewhere...
@CodeOpinion
@CodeOpinion Год назад
I'll give videos in the future with code examples.
@m1dway
@m1dway 2 года назад
I think that still part of SOLID principles only from business perspective. One class/module responsible for 1 thing
@CodeOpinion
@CodeOpinion 2 года назад
Define one "thing". Everyone seemingly has a different definition. I'd guess most would use the "one reason to change" but think of it technically rather than business requirements, which is how I think of it.
@m1dway
@m1dway 2 года назад
@@CodeOpinion exactly. "Thing" here is could be business department. For example, Product in marketing department, is different than product in warehouse department. This is the kind of single responsibility where people often misunderstand. They put all the product related behaviour in the same class
@awright18
@awright18 2 года назад
It feels like there is a small group of people that understand and practice this. I also wonder if this problem exists in most language ecosystems, traditionally OO languages, or if it is .NET specific.
@CodeOpinion
@CodeOpinion 2 года назад
My experience is it's industry wide on any platform/language/ecosystem
@JobertoDiniz
@JobertoDiniz 2 года назад
That’s make sense, except for the catalog service. Why would you replicate your catalog to each service using events? Each service would have the entire catalog data…
@CodeOpinion
@CodeOpinion 2 года назад
Why would or wouldn't you? I covered this in a video about event-carried state transfer (ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-IzBEbfSg0uY.html). But generally yes if it's more reference data from a supporting boundary, then sure. However often times most folks are concerned about replicating data when it's really just for View/UI composition, which is another topic that I need to cover.
@davec4197
@davec4197 Год назад
Is this basically microservices?
@CodeOpinion
@CodeOpinion Год назад
Microservices implies physical boundaries. Logical boundaries don't have to be physical boundaries
@MurtagBY
@MurtagBY Год назад
I feel like I completely don't get it after watching the video twice. The explanation jumps from high level to very high level and doesn't stop on explaining why high cohesion any better than low cohesion and strong coupling any worse than week coupling and what are the traid-offs. More abstract code often works out as a not needed and redundant layer which is easy to remove and get more imperative, simple code
@CodeOpinion
@CodeOpinion Год назад
Low cohesion will lead to high coupling. High coupling ultimately makes things more difficult to change. Check out this video, see if it helps: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-wRVbHDkOMSM.html
@MurtagBY
@MurtagBY Год назад
​@@CodeOpinion "Low cohesion will lead to high coupling. " = "If the degree of how well things belong together is low, it will lead to the degree of interdependence between modules being high" If many modules are interdependent - it means that overall system is hard to change. So, to reframe this - if a thing doesn't belong somewhere firmly - it belongs to everywhere and a system becomes a ball of mud (difficult to change) if a thing belongs to a certain part of the system firmly - you have a limited number of dependencies on it and it is easier to change. I see that often the dependences are sort of bi-directional if a certain service doesn't bother to wrap the data in it's own abstraction. e.g. a details of CRM system leak to billing through sales, where sales doesn't change things. Then as long as billing gets some information, over time it starts to build dependencies on it, first accidentally and then as a lowest friction path. - it is faster to put data through the whole stack in a single format and schema, rather then create representation on each. Then it becomes that all parts of the system depend on CRM for example. So the "Ce" is hiddenly very high
@pantsoff
@pantsoff 4 месяца назад
I mean, you basically just paraphrased "Clean Code" and the core concepts of "Clean Architecture" using fewer words. SOLID itself is just a set of principles that effectively target coupling and cohesion. I don't think any seasoned developer "thinks" about the individual components of SOLID on a day-to-day basis, but instead has uses a mental model that they have built up over the years through both experience and studying/relating to principles and frameworks laid out by smart people before them.
@CodeOpinion
@CodeOpinion 4 месяца назад
My point is that if you started with coupling and cohesion, which I assume most don't, and you start with the ways to to deal with them, you don't really know why you're doing what you're doing. "I don't think any seasoned developer "thinks" about the individual components of SOLID on a day-to-day basis". I don't think anyone can agree on what "seasoned" is anymore. 😂
@pantsoff
@pantsoff 4 месяца назад
@@CodeOpinion I certainly agree with your point... I think that is sort of what I'm getting at. I don't think anybody can really agree with what the word "clean" means anymore. At least most people can have a relatively common understanding of what the words "coupling" and "cohesion" mean, so it makes for a good reference point
@Euquila
@Euquila Год назад
I work alone, so: 1) NO unit tests, 2) NO integration tests, 3) code fast, 4) when pain sets in, take a step back and spend some time refactoring
Далее
Highly COHESIVE Software Design to tame Complexity
9:01
Аминка ❤️
00:16
Просмотров 827 тыс.
Event Carried State Transfer: Keep a local cache!
11:49
Event Sourcing Example & Explained in plain English
18:23
Coupling and Cohesion Explained
11:43
Просмотров 3,6 тыс.
Why is Clean Architecture so Popular?
11:52
Просмотров 48 тыс.
CRUD API + Complexity = Death by a 1000 Papercuts
12:40
Shared Database between Services? Maybe!
13:51
Просмотров 22 тыс.
Loose & Tight Coupling: Why Code is Hard to Change
17:40