Java for Fucking Idiots: Learn the Basics of Java Programming Without any experience!


package com.stevenbrown.memestore.app; public class



Download 3,91 Mb.
Pdf ko'rish
bet61/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   57   58   59   60   61   62   63   64   ...   70
Bog'liq
Java for Fucking Idiots

package
com.stevenbrown.memestore.app;
public class
MemeApp {
public static void
main(String[] args) {
}
}
This will come to you naturally in time. I swear. Trust fall?
How should I package my classes?
It’s totally up to you to decide the best way to organize all your classes. But
here’s some popular options people use:
1. Package by feature
2. Package by layer
3. Package by whatever the hell you feel like
Package by feature
If you like option 3 then you can skip the rest of this section for now.
Wimp.
What does this mean? A feature is, well, a feature of your software.
Something you provide that is valuable. For a piece of software that the
user actually sees, a feature might be a screen. Or collection of screens.
Imagine you’re creating a mobile application for Amazon, the future 4
th
branch of the U.S. government.
In a package by feature approach, we might have one top-level package for
each screen (and its related classes). Then, a package for everything else.
Product List
Product Detail
Shopping Cart
Account Settings
Shared


Database
Networking
That’s the structure in plain English (I like English). Here’s what it might
look like using all those packaging conventions we just went over:
Note that Amazon’s app would be wayyyyyyyy more complex than this.
Also I don’t work for them, and I don’t know how they structure their code.
But this is a simplistic example of a “package by feature” approach.
Each feature gets its own big boy package, and anything that isn’t quite a
feature is thrown together somewhere else.
Package by layer
Sure, package by “layer” … or whatever you want to call it. By
functionality, by purpose, etc.
In the last approach, “package by feature”, we had a package for each main
screen of the app…for each “feature” that we provide to the user.
In this approach, “package by layer”, we group by the kind of class it is. For
example, is the class part of the user interface? It goes in the userinterface
(ui) package.


Do you feel me? Are you feeling me?
“package by feature” – group things together by the section of your app or
whatever you would consider a “feature” of your program
“package by layer” – group things together solely by their function, whether
that be user interface, networking, helper classes, creating files, math, that
kind of stuff.
Let’s say there’s some networking related code I want to add that only
affects the ProductDetailScreen. Where would it go?
In Package by Feature, it goes in the productdetail package.
In Package by Layer, it goes into the networking package.
Imports
“It is clear our nation is reliant upon big foreign oil. More and more of our
imports come from overseas.”
– George W. Bush
This quote has nothing to do with anything.
But that last section took fucking forever and I want to reset our minds here.
Whew. Okay…
How do we let our classes interact with each other? What if the
ProductListScreen doesn’t know what products to show without first
making a network call to Amazon? Surely it needs to ask Amazon for


recommendations seeing as they know everything about every aspect of our
lives.
Can we just do something like this inside our ProductListScreen?
Networker networker =
new
Networker();
Response networkResponse = networker.getProductsToDisplay();

It seems reasonable, right? We know that we have a Networker class in our
project. Why wouldn’t we be able to create an object from that class? Why
can’t we just “instantiate” it willy nilly?
Because Java needs you to “import” it. Unless the class you want to use is
in the exact same package as yours, you must put an import statement at the
top of your Java file.
Remember package declarations? It’s the simple one-liner where you
specify what package your class belongs to.
Right below that, still at essentially the top of the file, you simply import all
the classes that you’ll need from outside this file.

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   57   58   59   60   61   62   63   64   ...   70




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish