This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

designing code based on SOLID principals

 
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Punit Jain wrote:But if the memory is empty, which means there are on service orders droid has. That's what I am checking at line 13.


You are trying to convince yourself that what you wrote is correct. That's not the correct mindset if you're looking for opportunities to refactor.  Your code has a smell. Rather than me telling you what that smell is, you should try to look harder and deeper, be more critical of the design and see what deficiency is there that's making me say there's a code smell. I know how to explain the problems I see in the code; the question is, do you?  You won't learn to swim if I keep holding your head above water, so I'll let you go and give you a chance to figure it out for yourself.
 
Junilu Lacar
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Punit Jain wrote:Agreed that my starting point should be focusing and writing the droid class. However, In the problem statement I am given to assume that there is already a droid which performs the task of maintaining and servicing vehicles. Nothing other than that.


Maybe you're working under more constraints than I'm assuming you have, I don't know. However, you're missing the point when you say there is already a droid that performs the task of maintaining and servicing vehicles. Even if there was already a droid, you're talking about a (hypothetical) physical device. This is a program you're trying to write and the Droid we're talking about designing is a (hypothetical) program entity that represents what the physical device does.

It's like how a physical Android phone has a software Android operating system that controls it. We're talking about Mechanic Droid (the program), not Mechanic Droid (the actual device).

The problem statement says "Create a program which helps the mechanic droid track each vehicle that has been serviced and store the information until it can be uploaded to a central repository."  There are no constraints in that requirement that would prevent me from saying that the droid uses ServiceOrder objects that have information about the Vehicle being serviced and other things related to the service work. Even if we say we don't want to track any of the service work done but only track which vehicles have been serviced, I'd still go with a ServiceOrder that included Vehicle information on it.  At most, I'd only replicate the Vehicle's unique identifier and perhaps a short description of the Vehicle in the Service Order. Then again, maybe it's just me and the heuristics that I employ when designing. I'm pretty sure that tracking Vehicles won't be the only thing this droid will be asked to do while its offline and working independently, so the Service Order is a hedge. I'm betting that since using a Service Order already makes sense to me now, it will still make sense later when more requirements come in to extend the capabilities of the Droid program.
 
Ranch Hand
Posts: 1102
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Punit Jain wrote:Agreed that my starting point should be focusing and writing the droid class. However, In the problem statement I am given to assume that there is already a droid which performs the task of maintaining and servicing vehicles. Nothing other than that.


Maybe you're working under more constraints than I'm assuming you have, I don't know. However, you're missing the point when you say there is already a droid that performs the task of maintaining and servicing vehicles. Even if there was already a droid, you're talking about a (hypothetical) physical device. This is a program you're trying to write and the Droid we're talking about designing is a (hypothetical) program entity that represents what the physical device does.

It's like how a physical Android phone has a software Android operating system that controls it. We're talking about Mechanic Droid (the program), not Mechanic Droid (the actual device).

The problem statement says "Create a program which helps the mechanic droid track each vehicle that has been serviced and store the information until it can be uploaded to a central repository."  There are no constraints in that requirement that would prevent me from saying that the droid uses ServiceOrder objects that have information about the Vehicle being serviced and other things related to the service work. Even if we say we don't want to track any of the service work done but only track which vehicles have been serviced, I'd still go with a ServiceOrder that included Vehicle information on it.  At most, I'd only replicate the Vehicle's unique identifier and perhaps a short description of the Vehicle in the Service Order. Then again, maybe it's just me and the heuristics that I employ when designing. I'm pretty sure that tracking Vehicles won't be the only thing this droid will be asked to do while its offline and working independently, so the Service Order is a hedge. I'm betting that since using a Service Order already makes sense to me now, it will still make sense later when more requirements come in to extend the capabilities of the Droid program.



Agree. tracking order is not the only thing the droid is supposed to do, however in the problem statement I was was asked to design a program for tracking order only.

Also, possible that I misinterpreted the requirements and as you said that the droid could also be just a physical entity in the given problem statement and I could have a scope to write a droid class as well.      
 
Punit Jain
Ranch Hand
Posts: 1102
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Punit Jain wrote:
1.) At line 47, the display name says about outstanding order but the method name is order received.
2.) At line 57, instead of using greater than I could have check for the exact number.
3.) Again the method name and display names are inconsistent at line 54 and 55.


This is only scratching the surface. On #2 above, your suggested mitigation would make the smell worse.

Try harder and look at the example of what I did to highlight the smells in my own tests.



Hmm. Because I was limited to only tracking. However, if I have chance to write droid as well or have bit more freedom. Following is a little improved version:

 
Junilu Lacar
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't think you're getting it still. That doesn't look like an improvement to me at all. If anything, it's moving in the wrong direction. Sorry. ¯\_(ツ)_/¯

Program design is tough. Writing coherent code is tough. It takes a lot of practice, so I'll let you go and get in more reps. Check back again if you have more code you'd like me to comment on, if you don't mind taking my blunt critiques.  I don't know what kind of books you use as references but here are some of the books that taught me most of what I know about design:

"Understanding the Four Rules of Simple Design" by Corey Haines
Books by Kent Beck on JUnit and Test-Driven Development
"Refactoring" by Martin Fowler. Also, books in Fowler's Signature Series about Enterprise Architecture Patterns
Books by Robert "Uncle Bob" Martin - Clean Code, Agile Software Development - Principles, Patterns, and Practices
Craig Larman - "Object-Oriented Analysis and Design"
Growing Object-Oriented Software Guided By Tests by Nat Pryce and Steve Freeman
The Pragmatic Programmer by Andrew Hunt and David Thomas.
Refactoring to Patterns by Joshua Kerievsky

and others by authors like Tom Gilb, Steve McConnell, Peter Coad, Alistair Cockburn, and many more
 
Punit Jain
Ranch Hand
Posts: 1102
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:No, I don't think you're getting it still. That doesn't look like an improvement to me at all. If anything, it's moving in the wrong direction. Sorry. ¯\_(ツ)_/¯

Program design is tough. Writing coherent code is tough. It takes a lot of practice, so I'll let you go and get in more reps. Check back again if you have more code you'd like me to comment on, if you don't mind taking my blunt critiques.  I don't know what kind of books you use as references but here are some of the books that taught me most of what I know about design:

"Understanding the Four Rules of Simple Design" by Corey Haines
Books by Kent Beck on JUnit and Test-Driven Development
"Refactoring" by Martin Fowler. Also, books in Fowler's Signature Series about Enterprise Architecture Patterns
Books by Robert "Uncle Bob" Martin - Clean Code, Agile Software Development - Principles, Patterns, and Practices
Craig Larman - "Object-Oriented Analysis and Design"
Growing Object-Oriented Software Guided By Tests by Nat Pryce and Steve Freeman
The Pragmatic Programmer by Andrew Hunt and David Thomas.
Refactoring to Patterns by Joshua Kerievsky

and others by authors like Tom Gilb, Steve McConnell, Peter Coad, Alistair Cockburn, and many more



Hmmm.. Alright let me get these books from my college library and go through them.

Yes, I will be in need of your comments on my code, once I go through these books.

 
Punit Jain
Ranch Hand
Posts: 1102
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Check back again if you have more code you'd like me to comment on, if you don't mind taking my blunt critiques.



I won't mind as long as they help me to learn.
 
Junilu Lacar
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing about those books: I've never read any of them straight from cover to cover, with perhaps a couple of exceptions:

1. Kent Beck's first book on Extreme Programming, "Extreme Programming Explained - Embrace Change" -- this is the manifesto of XP. I read this cover to cover in late 1999-2000.

2. Corey Haines' "Understanding the Four Rules of Simple Design" - I read it cover to cover (well, first to the last page since it is an ebook) because it only has 70+ pages and it's so full of great techniques and insights that I couldn't stop reading it.

3. Andy Hunt and Dave Thomas' "The Pragmatic Programmer - From Journeyman to Master" - again because it's not a very thick book and it's full of great advice.

I have never read any of the other books through and through, cover to cover, not even one of my favorites, "Clean Code".

Another book that I really like that I think every serious programmer should read is "Pragmatic Thinking & Learning - Refactor Your Wetware" by Andrew Hunt.  It's not about design or even programming per se. Rather, it's a treatise on how we humans think and learn and how we, through better self-awareness, can become better learners. Being a programmer means you're going to be subjected to a constant and continuous learning process. The more you know how to learn better, the better you'll get at programming and developing software.
 
Punit Jain
Ranch Hand
Posts: 1102
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. Thanks a lot.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!